-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lua4jvm: Replace hidden classes with single-use ClassLoaders
Hidden classes have hidden stack frames, which is not ok when they are compiled from user code that might throw exceptions.
- Loading branch information
Showing
5 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
lua4jvm/src/main/java/fi/benjami/code4jvm/lua/compiler/ClassData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package fi.benjami.code4jvm.lua.compiler; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
import fi.benjami.code4jvm.Type; | ||
import fi.benjami.code4jvm.call.CallTarget; | ||
import fi.benjami.code4jvm.call.FixedCallTarget; | ||
|
||
/** | ||
* Support code for custom class data dynamic constants. | ||
* JDK already has {@link MethodHandles#classDataAt(java.lang.invoke.MethodHandles.Lookup, String, Class, int) a form of this}, | ||
* but it only works with actual JDK class data. That, unfortunately, is only | ||
* available for hidden classes, which we can't use because they're invisible | ||
* in stack frames... | ||
* | ||
*/ | ||
public class ClassData { | ||
|
||
static final String FIELD_NAME = "$CONSTANTS"; | ||
static final FixedCallTarget BOOTSTRAP = CallTarget.staticMethod(Type.of(ClassData.class), Type.OBJECT, "get", | ||
Type.of(MethodHandles.Lookup.class), Type.STRING, Type.of(Class.class), Type.INT); | ||
|
||
public static Object get(MethodHandles.Lookup lookup, String ignoredName, Class<?> type, int index) { | ||
Object[] array; | ||
try { | ||
array = (Object[]) lookup.findStaticGetter(lookup.lookupClass(), FIELD_NAME, Object[].class) | ||
.invokeExact(); | ||
} catch (Throwable e) { | ||
throw new AssertionError(e); | ||
} | ||
return array[index]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters