changeset 5602:e79b593e0632

made NewInstanceSnippets respect the UseTLAB HotSpot option removed redundant formatting of new instances created by calling the runtime (the runtime call does this already)
author Doug Simon <doug.simon@oracle.com>
date Thu, 14 Jun 2012 14:03:28 +0200
parents e1aa23322006
children dbd82d1edce6
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewInstanceSnippets.java src/share/vm/graal/graalCompilerToVM.cpp
diffstat 4 files changed, 38 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Thu Jun 14 14:01:37 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Thu Jun 14 14:03:28 2012 +0200
@@ -41,6 +41,7 @@
     public boolean useFastLocking;
     public boolean useFastNewObjectArray;
     public boolean useFastNewTypeArray;
+    public boolean useTLAB;
 
     // offsets, ...
     public int vmPageSize;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Thu Jun 14 14:01:37 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Thu Jun 14 14:03:28 2012 +0200
@@ -75,7 +75,7 @@
         installer.install(CheckCastSnippets.class);
         installer.install(NewInstanceSnippets.class);
         checkcastSnippets = new CheckCastSnippets.Templates(this);
-        newInstanceSnippets = new NewInstanceSnippets.Templates(this);
+        newInstanceSnippets = new NewInstanceSnippets.Templates(this, config.useTLAB);
     }
 
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewInstanceSnippets.java	Thu Jun 14 14:01:37 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewInstanceSnippets.java	Thu Jun 14 14:03:28 2012 +0200
@@ -61,28 +61,43 @@
      * Type test used when the type being tested against is a final type.
      */
     @Snippet
-    public static Object newInstance(@Parameter("hub") Object hub, @ConstantParameter("size") int size, @ConstantParameter("checkInit") boolean checkInit, @ConstantParameter("logType") String logType) {
+    public static Object newInstance(
+                    @Parameter("hub") Object hub,
+                    @ConstantParameter("size") int size,
+                    @ConstantParameter("checkInit") boolean checkInit,
+                    @ConstantParameter("useTLAB") boolean useTLAB,
+                    @ConstantParameter("logType") String logType) {
+
         if (checkInit) {
             int klassState = load(hub, 0, klassStateOffset(), Kind.Int);
             if (klassState != klassStateFullyInitialized()) {
-                Object instance = NewInstanceStubCall.call(hub);
-                return formatInstance(hub, size, instance, logType);
+                if (logType != null) {
+                    Log.print(logType);
+                    Log.println(" - uninitialized");
+                }
+                return NewInstanceStubCall.call(hub);
             }
         }
 
-        Word thread = asWord(register(r15, wordKind()));
-        Word top = loadWord(thread, threadTlabTopOffset());
-        Word end = loadWord(thread, threadTlabEndOffset());
-        Word newTop = top.plus(size);
-        Object instance;
-        if (newTop.cmp(BE, end)) {
-            instance = cast(top, Object.class);
-            store(thread, 0, threadTlabTopOffset(), newTop);
+        if (useTLAB) {
+            Word thread = asWord(register(r15, wordKind()));
+            Word top = loadWord(thread, threadTlabTopOffset());
+            Word end = loadWord(thread, threadTlabEndOffset());
+            Word newTop = top.plus(size);
+            if (newTop.cmp(BE, end)) {
+                Object instance = cast(top, Object.class);
+                store(thread, 0, threadTlabTopOffset(), newTop);
+                return formatInstance(hub, size, instance, logType);
+            } else {
+                if (logType != null) {
+                    Log.print(logType);
+                    Log.println(" - stub allocate");
+                }
+                return NewInstanceStubCall.call(hub);
+            }
         } else {
-            instance = NewInstanceStubCall.call(hub);
+            return NewInstanceStubCall.call(hub);
         }
-
-        return formatInstance(hub, size, instance, logType);
     }
 
     private static Word asWord(Object object) {
@@ -158,12 +173,14 @@
         private final Cache cache;
         private final ResolvedJavaMethod newInstance;
         private final CodeCacheProvider runtime;
+        private final boolean useTLAB;
 
-        public Templates(CodeCacheProvider runtime) {
+        public Templates(CodeCacheProvider runtime, boolean useTLAB) {
             this.runtime = runtime;
             this.cache = new Cache(runtime);
+            this.useTLAB = useTLAB;
             try {
-                newInstance = runtime.getResolvedJavaMethod(NewInstanceSnippets.class.getDeclaredMethod("newInstance", Object.class, int.class, boolean.class, String.class));
+                newInstance = runtime.getResolvedJavaMethod(NewInstanceSnippets.class.getDeclaredMethod("newInstance", Object.class, int.class, boolean.class, boolean.class, String.class));
             } catch (NoSuchMethodException e) {
                 throw new GraalInternalError(e);
             }
@@ -178,10 +195,11 @@
             HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) newInstanceNode.instanceClass();
             HotSpotKlassOop hub = type.klassOop();
             int instanceSize = type.instanceSize();
-            Key key = new Key(newInstance).add("size", instanceSize).add("checkInit", !type.isInitialized()).add("logType", LOG_ALLOCATION ? type.name() : null);
+            Key key = new Key(newInstance).add("size", instanceSize).add("checkInit", !type.isInitialized()).add("useTLAB", useTLAB).add("logType", LOG_ALLOCATION ? type.name() : null);
             Arguments arguments = arguments("hub", hub);
             SnippetTemplate template = cache.get(key);
             Debug.log("Lowering newInstance in %s: node=%s, template=%s, arguments=%s", graph, newInstanceNode, template, arguments);
+            //System.out.printf("Lowering newInstance in %s: node=%s, template=%s, arguments=%s%n", graph, newInstanceNode, template, arguments);
             template.instantiate(runtime, newInstanceNode, newInstanceNode, arguments);
             new DeadCodeEliminationPhase().apply(graph);
         }
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Thu Jun 14 14:01:37 2012 +0200
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Thu Jun 14 14:03:28 2012 +0200
@@ -785,6 +785,7 @@
   set_boolean(env, config, "useFastLocking", UseFastLocking);
   set_boolean(env, config, "useFastNewObjectArray", UseFastNewObjectArray);
   set_boolean(env, config, "useFastNewTypeArray", UseFastNewTypeArray);
+  set_boolean(env, config, "useTLAB", UseTLAB);
   set_int(env, config, "codeEntryAlignment", CodeEntryAlignment);
   set_int(env, config, "vmPageSize", os::vm_page_size());
   set_int(env, config, "stackShadowPages", StackShadowPages);