Skip to content

Commit

Permalink
Store array and foreign shapes in instance fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
ansalond committed May 17, 2021
1 parent 5757143 commit dfca9fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,17 @@ public final class EspressoLanguage extends TruffleLanguage<EspressoContext> imp

private ClassLoader cl;

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
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
// SubstrateVM feature which will allow us to set the right field offsets at image build time.
@CompilerDirectives.CompilationFinal //
private static StaticShape<StaticObjectFactory> arrayShape;
private StaticShape<StaticObjectFactory> arrayShape;

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
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
// SubstrateVM feature which will allow us to set the right field offsets at image build time.
@CompilerDirectives.CompilationFinal //
private static StaticShape<StaticObjectFactory> foreignShape;
private StaticShape<StaticObjectFactory> foreignShape;

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

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

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

@CompilerDirectives.TruffleBoundary
private static synchronized void initializeArrayShape() {
private synchronized void initializeArrayShape() {
if (arrayShape == null) {
arrayShape = StaticShape.newBuilder(staticCLC).property(ARRAY_PROPERTY).build(StaticObject.class, StaticObjectFactory.class);
arrayShape = StaticShape.newBuilder(this).property(arrayProperty).build(StaticObject.class, StaticObjectFactory.class);
}
}

public static StaticProperty getForeignProperty() {
return FOREIGN_PROPERTY;
public StaticProperty getForeignProperty() {
return foreignProperty;
}

public static StaticShape<StaticObjectFactory> getForeignShape() {
public StaticShape<StaticObjectFactory> getForeignShape() {
if (foreignShape == null) {
initializeForeignShape();
}
return foreignShape;
}

@CompilerDirectives.TruffleBoundary
private static synchronized void initializeForeignShape() {
private synchronized void initializeForeignShape() {
if (foreignShape == null) {
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;
foreignShape = StaticShape.newBuilder(this).property(foreignProperty).build(StaticObject.class, StaticObjectFactory.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ public static StaticObject createArray(ArrayKlass klass, Object array) {
assert array != null;
assert !(array instanceof StaticObject);
assert array.getClass().isArray();
StaticObject newObj = EspressoLanguage.getArrayShape().getFactory().create(klass);
EspressoLanguage.getArrayProperty().setObject(newObj, array);
EspressoLanguage espresso = klass.getEspressoLanguage();
StaticObject newObj = espresso.getArrayShape().getFactory().create(klass);
espresso.getArrayProperty().setObject(newObj, array);
return trackAllocation(klass, newObj);
}

Expand Down Expand Up @@ -178,10 +179,10 @@ public static StaticObject createForeignNull(Klass klass, Object foreignObject)
}

private static StaticObject createForeign(Klass klass, Object foreignObject, boolean isNull) {
assert klass != null;
assert foreignObject != null;
StaticObject newObj = EspressoLanguage.getForeignShape().getFactory().create(klass, true, isNull);
EspressoLanguage.getForeignProperty().setObject(newObj, foreignObject);
EspressoLanguage espresso = klass.getEspressoLanguage();
StaticObject newObj = espresso.getForeignShape().getFactory().create(klass, true, isNull);
espresso.getForeignProperty().setObject(newObj, foreignObject);
return trackAllocation(klass, newObj);
}

Expand Down Expand Up @@ -310,7 +311,7 @@ public boolean isEspressoObject() {

public Object rawForeignObject() {
assert isForeignObject();
return EspressoLanguage.getForeignProperty().getObject(this);
return getKlass().getEspressoLanguage().getForeignProperty().getObject(this);
}

public boolean isStaticStorage() {
Expand Down Expand Up @@ -395,7 +396,7 @@ public String toVerboseString() {
* Start of Array manipulation.
*/
private Object getArray() {
return EspressoLanguage.getArrayProperty().getObject(this);
return getKlass().getEspressoLanguage().getArrayProperty().getObject(this);
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit dfca9fc

Please sign in to comment.