Skip to content

Commit

Permalink
[GR-26081] Reset DynamicObject layout cache after native image genera…
Browse files Browse the repository at this point in the history
…tion.

PullRequest: graal/7106
  • Loading branch information
woess committed Sep 11, 2020
2 parents 69c013f + c5d0b04 commit 17acccd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ public void cleanup() {
invokeStaticMethod("com.oracle.truffle.api.library.LibraryFactory", "resetNativeImageState", Collections.emptyList());
invokeStaticMethod("com.oracle.truffle.api.nodes.Node", "resetNativeImageState", Collections.emptyList());
invokeStaticMethod("com.oracle.truffle.api.source.Source", "resetNativeImageState", Collections.emptyList());
// clean up cached object layouts
invokeStaticMethod("com.oracle.truffle.object.LayoutImpl", "resetNativeImageState", Collections.emptyList());
}

public static boolean useTruffleCompiler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ public Layout createLayout(Builder layoutBuilder) {
return DefaultLayout.createCoreLayout(layoutBuilder);
}

public Property createProperty(Object id, Location location) {
public final Property createProperty(Object id, Location location) {
return createProperty(id, location, 0);
}

public Property createProperty(Object id, Location location, int flags) {
public final Property createProperty(Object id, Location location, int flags) {
return new PropertyImpl(id, location, flags);
}

public int getPriority() {
return 10;
}

protected void resetNativeImageState() {
DefaultLayout.resetNativeImageState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,12 @@ public String toString() {
return "LayoutInfo [objectFields=" + Arrays.toString(objectFields) + ", primitiveFields=" + Arrays.toString(primitiveFields) + "]";
}
}

/**
* Resets the state for native image generation.
*/
static void resetNativeImageState() {
LAYOUT_MAP.clear();
LayoutInfo.LAYOUT_INFO_MAP.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Objects;

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.TruffleOptions;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.Layout;
import com.oracle.truffle.api.object.Location;
Expand Down Expand Up @@ -156,6 +157,16 @@ public String toString() {
return "Layout[" + clazz.getName() + "]";
}

/**
* Resets the state for native image generation.
*
* NOTE: this method is called reflectively by downstream projects.
*/
static void resetNativeImageState() {
assert TruffleOptions.AOT : "Only supported during image generation";
((CoreLayoutFactory) getFactory()).resetNativeImageState();
}

@SuppressWarnings("static-method")
protected abstract static class Support extends Access {
protected Support() {
Expand Down
4 changes: 2 additions & 2 deletions vm/mx.vm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"name": "graal-nodejs",
"subdir": True,
"dynamic": True,
"version": "1858e4e91b63d5c2f7731ac5aa0d236f4d39866a",
"version": "53ecef240665238a6655df7df8b6012df39107c6",
"urls" : [
{"url" : "https://github.com/graalvm/graaljs.git", "kind" : "git"},
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
Expand All @@ -49,7 +49,7 @@
"name": "graal-js",
"subdir": True,
"dynamic": True,
"version": "1858e4e91b63d5c2f7731ac5aa0d236f4d39866a",
"version": "53ecef240665238a6655df7df8b6012df39107c6",
"urls": [
{"url": "https://github.com/graalvm/graaljs.git", "kind" : "git"},
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
Expand Down

0 comments on commit 17acccd

Please sign in to comment.