changeset 22738:359f60a0a457

Truffle: defer lookup of call methods
author Andreas Woess <andreas.woess@oracle.com>
date Wed, 30 Sep 2015 16:46:33 +0200
parents 5e8c004f5358
children dd513aa0a563
files graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java
diffstat 2 files changed, 36 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Wed Sep 30 16:19:48 2015 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Wed Sep 30 16:46:33 2015 +0200
@@ -127,7 +127,6 @@
 
     private HotSpotTruffleRuntime() {
         setDontInlineCallBoundaryMethod();
-        lookupCallMethods(getHotSpotProviders().getMetaAccess());
 
         installDefaultListeners();
 
@@ -380,11 +379,19 @@
     }
 
     @Override
-    public boolean platformEnableInfopoints() {
+    protected boolean platformEnableInfopoints() {
         return getCodeCache().shouldDebugNonSafepoints();
     }
 
     @Override
+    protected CallMethods getCallMethods() {
+        if (callMethods == null) {
+            lookupCallMethods(getHotSpotProviders().getMetaAccess());
+        }
+        return callMethods;
+    }
+
+    @Override
     public Collection<RootCallTarget> getCallTargets() {
         return Collections.unmodifiableSet(callTargets.keySet());
     }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java	Wed Sep 30 16:19:48 2015 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java	Wed Sep 30 16:46:33 2015 +0200
@@ -75,15 +75,12 @@
     private ArrayList<String> includes;
     private ArrayList<String> excludes;
 
-    protected ResolvedJavaMethod[] callNodeMethod;
-    protected ResolvedJavaMethod[] callTargetMethod;
-    protected ResolvedJavaMethod[] anyFrameMethod;
-
     private final List<GraalTruffleCompilationListener> compilationListeners = new ArrayList<>();
     private final GraalTruffleCompilationListener compilationNotify = new DispatchTruffleCompilationListener();
 
     protected TruffleCompiler truffleCompiler;
     protected LoopNodeFactory loopNodeFactory;
+    protected CallMethods callMethods;
 
     public GraalTruffleRuntime() {
         Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
@@ -125,9 +122,7 @@
     }
 
     protected void lookupCallMethods(MetaAccessProvider metaAccess) {
-        callNodeMethod = new ResolvedJavaMethod[]{metaAccess.lookupJavaMethod(GraalFrameInstance.CallNodeFrame.METHOD)};
-        callTargetMethod = new ResolvedJavaMethod[]{metaAccess.lookupJavaMethod(GraalFrameInstance.CallTargetFrame.METHOD)};
-        anyFrameMethod = new ResolvedJavaMethod[]{callNodeMethod[0], callTargetMethod[0]};
+        callMethods = CallMethods.lookup(metaAccess);
     }
 
     @Override
@@ -207,22 +202,22 @@
 
             public T visitFrame(InspectedFrame frame) {
                 if (skipNext) {
-                    assert frame.isMethod(callTargetMethod[0]);
+                    assert frame.isMethod(getCallMethods().callTargetMethod[0]);
                     skipNext = false;
                     return null;
                 }
 
-                if (frame.isMethod(callNodeMethod[0])) {
+                if (frame.isMethod(getCallMethods().callNodeMethod[0])) {
                     skipNext = true;
                     return visitor.visitFrame(new GraalFrameInstance.CallNodeFrame(frame));
                 } else {
-                    assert frame.isMethod(callTargetMethod[0]);
+                    assert frame.isMethod(getCallMethods().callTargetMethod[0]);
                     return visitor.visitFrame(new GraalFrameInstance.CallTargetFrame(frame, false));
                 }
 
             }
         };
-        return stackIntrospection.iterateFrames(anyFrameMethod, anyFrameMethod, 1, inspectedFrameVisitor);
+        return stackIntrospection.iterateFrames(getCallMethods().anyFrameMethod, getCallMethods().anyFrameMethod, 1, inspectedFrameVisitor);
     }
 
     protected abstract StackIntrospection getStackIntrospection();
@@ -235,7 +230,7 @@
     @TruffleBoundary
     @Override
     public FrameInstance getCurrentFrame() {
-        return getStackIntrospection().iterateFrames(callTargetMethod, callTargetMethod, 0, frame -> new GraalFrameInstance.CallTargetFrame(frame, true));
+        return getStackIntrospection().iterateFrames(getCallMethods().callTargetMethod, getCallMethods().callTargetMethod, 0, frame -> new GraalFrameInstance.CallTargetFrame(frame, true));
     }
 
     public <T> T getCapability(Class<T> capability) {
@@ -329,6 +324,10 @@
 
     protected abstract boolean platformEnableInfopoints();
 
+    protected CallMethods getCallMethods() {
+        return callMethods;
+    }
+
     private final class DispatchTruffleCompilationListener implements GraalTruffleCompilationListener {
 
         public void notifyCompilationQueued(OptimizedCallTarget target) {
@@ -376,4 +375,20 @@
         }
 
     }
+
+    protected static final class CallMethods {
+        protected final ResolvedJavaMethod[] callNodeMethod;
+        protected final ResolvedJavaMethod[] callTargetMethod;
+        protected final ResolvedJavaMethod[] anyFrameMethod;
+
+        private CallMethods(MetaAccessProvider metaAccess) {
+            this.callNodeMethod = new ResolvedJavaMethod[]{metaAccess.lookupJavaMethod(GraalFrameInstance.CallNodeFrame.METHOD)};
+            this.callTargetMethod = new ResolvedJavaMethod[]{metaAccess.lookupJavaMethod(GraalFrameInstance.CallTargetFrame.METHOD)};
+            this.anyFrameMethod = new ResolvedJavaMethod[]{callNodeMethod[0], callTargetMethod[0]};
+        }
+
+        public static CallMethods lookup(MetaAccessProvider metaAccess) {
+            return new CallMethods(metaAccess);
+        }
+    }
 }