Skip to content

Commit

Permalink
Revert "Store array and foreign shapes in instance fields."
Browse files Browse the repository at this point in the history
This reverts commit d1fa8c7.
  • Loading branch information
ansalond committed May 17, 2021
1 parent 0891987 commit ca44c1c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,19 @@ public final class EspressoLanguage extends TruffleLanguage<EspressoContext> 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<StaticObjectFactory> arrayShape;
private static StaticShape<StaticObjectFactory> 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<StaticObjectFactory> foreignShape;
private static StaticShape<StaticObjectFactory> foreignShape;

public EspressoLanguage() {
// Initialize statically defined symbols and substitutions.
Expand Down Expand Up @@ -241,39 +243,53 @@ public ClassLoader getClassLoader() {
return cl;
}

public StaticProperty getArrayProperty() {
return arrayProperty;
public static StaticProperty getArrayProperty() {
return ARRAY_PROPERTY;
}

public StaticShape<StaticObjectFactory> getArrayShape() {
public static StaticShape<StaticObjectFactory> getArrayShape() {
if (arrayShape == null) {
initializeArrayShape();
}
return arrayShape;
}

@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<StaticObjectFactory> getForeignShape() {
public static StaticShape<StaticObjectFactory> getForeignShape() {
if (foreignShape == null) {
initializeForeignShape();
}
return foreignShape;
}

@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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit ca44c1c

Please sign in to comment.