From ca44c1cb4d260f6bc895c38599405578bcd77eac Mon Sep 17 00:00:00 2001 From: Danilo Ansaloni Date: Mon, 17 May 2021 21:20:36 +0200 Subject: [PATCH] Revert "Store array and foreign shapes in instance fields." This reverts commit d1fa8c7edcde77598e6b7f21d0d5b827753e5145. --- .../truffle/espresso/EspressoLanguage.java | 48 ++++++++++++------- .../nodes/interop/ToEspressoNode.java | 2 +- .../espresso/runtime/StaticObject.java | 24 +++++----- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoLanguage.java b/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoLanguage.java index e1422844f35a..7a3b55a3cf2f 100644 --- a/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoLanguage.java +++ b/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoLanguage.java @@ -93,17 +93,19 @@ public final class EspressoLanguage extends TruffleLanguage imp private ClassLoader cl; - private final StaticProperty arrayProperty = new DefaultStaticProperty("array", StaticPropertyKind.Object, true); - // This field should be final, but until we move the static object model we cannot have a + private static final StaticClassLoaderCache staticCLC = new StaticClassLoaderCache(); + + private static final StaticProperty ARRAY_PROPERTY = new DefaultStaticProperty("array", StaticPropertyKind.Object, true); + // This field should be static final, but until we move the static object model we cannot have a // SubstrateVM feature which will allow us to set the right field offsets at image build time. @CompilerDirectives.CompilationFinal // - private StaticShape arrayShape; + private static StaticShape arrayShape; - private final StaticProperty foreignProperty = new DefaultStaticProperty("foreignObject", StaticPropertyKind.Object, true); - // This field should be final, but until we move the static object model we cannot have a + private static final StaticProperty FOREIGN_PROPERTY = new DefaultStaticProperty("foreignObject", StaticPropertyKind.Object, true); + // This field should be static final, but until we move the static object model we cannot have a // SubstrateVM feature which will allow us to set the right field offsets at image build time. @CompilerDirectives.CompilationFinal // - private StaticShape foreignShape; + private static StaticShape foreignShape; public EspressoLanguage() { // Initialize statically defined symbols and substitutions. @@ -241,11 +243,11 @@ public ClassLoader getClassLoader() { return cl; } - public StaticProperty getArrayProperty() { - return arrayProperty; + public static StaticProperty getArrayProperty() { + return ARRAY_PROPERTY; } - public StaticShape getArrayShape() { + public static StaticShape getArrayShape() { if (arrayShape == null) { initializeArrayShape(); } @@ -253,17 +255,17 @@ public StaticShape getArrayShape() { } @CompilerDirectives.TruffleBoundary - private synchronized void initializeArrayShape() { + private static synchronized void initializeArrayShape() { if (arrayShape == null) { - arrayShape = StaticShape.newBuilder(this).property(arrayProperty).build(StaticObject.class, StaticObjectFactory.class); + arrayShape = StaticShape.newBuilder(staticCLC).property(ARRAY_PROPERTY).build(StaticObject.class, StaticObjectFactory.class); } } - public StaticProperty getForeignProperty() { - return foreignProperty; + public static StaticProperty getForeignProperty() { + return FOREIGN_PROPERTY; } - public StaticShape getForeignShape() { + public static StaticShape getForeignShape() { if (foreignShape == null) { initializeForeignShape(); } @@ -271,9 +273,23 @@ public StaticShape getForeignShape() { } @CompilerDirectives.TruffleBoundary - private synchronized void initializeForeignShape() { + private static synchronized void initializeForeignShape() { if (foreignShape == null) { - foreignShape = StaticShape.newBuilder(this).property(foreignProperty).build(StaticObject.class, StaticObjectFactory.class); + foreignShape = StaticShape.newBuilder(staticCLC).property(FOREIGN_PROPERTY).build(StaticObject.class, StaticObjectFactory.class); + } + } + + private static class StaticClassLoaderCache implements ClassLoaderCache { + private ClassLoader cl; + + @Override + public void setClassLoader(ClassLoader cl) { + this.cl = cl; + } + + @Override + public ClassLoader getClassLoader() { + return cl; } } } diff --git a/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToEspressoNode.java b/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToEspressoNode.java index 02b157db1845..a620979c9294 100644 --- a/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToEspressoNode.java +++ b/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToEspressoNode.java @@ -157,7 +157,7 @@ static boolean isForeignException(Klass klass) { @SuppressWarnings("unused") @Specialization(guards = {"!isStaticObject(value)", "interop.isNull(value)", "!klass.isPrimitive()"}) Object doForeignNull(Object value, Klass klass, @CachedLibrary(limit = "LIMIT") InteropLibrary interop, @CachedContext(EspressoLanguage.class) EspressoContext context) { - return StaticObject.createForeignNull(context.getLanguage(), value); + return StaticObject.createForeignNull(value); } @Specialization(guards = {"isStringCompatible(klass)"}) diff --git a/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/StaticObject.java b/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/StaticObject.java index 4b3856fda3bd..85cb82ebe0bb 100644 --- a/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/StaticObject.java +++ b/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/StaticObject.java @@ -141,9 +141,8 @@ public static StaticObject createArray(ArrayKlass klass, Object array) { assert array != null; assert !(array instanceof StaticObject); assert array.getClass().isArray(); - EspressoLanguage espresso = klass.getEspressoLanguage(); - StaticObject newObj = espresso.getArrayShape().getFactory().create(klass); - espresso.getArrayProperty().setObject(newObj, array); + StaticObject newObj = EspressoLanguage.getArrayShape().getFactory().create(klass); + EspressoLanguage.getArrayProperty().setObject(newObj, array); return trackAllocation(klass, newObj); } @@ -160,22 +159,21 @@ public static StaticObject createArray(ArrayKlass klass, Object array) { } public static StaticObject createForeign(Klass klass, Object foreignObject, InteropLibrary interopLibrary) { - EspressoLanguage espresso = klass.getEspressoLanguage(); if (interopLibrary.isNull(foreignObject)) { - return createForeignNull(espresso, foreignObject); + return createForeignNull(foreignObject); } - return createForeign(espresso, klass, foreignObject); + return createForeign(klass, foreignObject); } - public static StaticObject createForeignNull(EspressoLanguage espresso, Object foreignObject) { + public static StaticObject createForeignNull(Object foreignObject) { assert InteropLibrary.getUncached().isNull(foreignObject); - return createForeign(espresso, null, foreignObject); + return createForeign(null, foreignObject); } - private static StaticObject createForeign(EspressoLanguage espresso, Klass klass, Object foreignObject) { + private static StaticObject createForeign(Klass klass, Object foreignObject) { assert foreignObject != null; - StaticObject newObj = espresso.getForeignShape().getFactory().create(klass, true); - espresso.getForeignProperty().setObject(newObj, foreignObject); + StaticObject newObj = EspressoLanguage.getForeignShape().getFactory().create(klass, true); + EspressoLanguage.getForeignProperty().setObject(newObj, foreignObject); return trackAllocation(klass, newObj); } @@ -302,7 +300,7 @@ public boolean isEspressoObject() { public Object rawForeignObject(EspressoLanguage espresso) { assert isForeignObject(); - return espresso.getForeignProperty().getObject(this); + return EspressoLanguage.getForeignProperty().getObject(this); } public boolean isStaticStorage() { @@ -387,7 +385,7 @@ public String toVerboseString() { * Start of Array manipulation. */ private Object getArray() { - return getKlass().getEspressoLanguage().getArrayProperty().getObject(this); + return EspressoLanguage.getArrayProperty().getObject(this); } @SuppressWarnings("unchecked")