changeset 7237:509d72a1d81b

made the effect of graal.logNewArrayStub independent from graal.logNewInstanceStub
author Doug Simon <doug.simon@oracle.com>
date Mon, 17 Dec 2012 11:29:06 +0100
parents 579ee1eb0f30
children 7f55fd5f897d
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java
diffstat 2 files changed, 52 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java	Mon Dec 17 11:12:25 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java	Mon Dec 17 11:29:06 2012 +0100
@@ -53,7 +53,7 @@
     protected void populateKey(Key key) {
         HotSpotResolvedObjectType intArrayType = (HotSpotResolvedObjectType) runtime.lookupJavaType(int[].class);
         Constant intArrayHub = intArrayType.klass();
-        key.add("intArrayHub", intArrayHub);
+        key.add("intArrayHub", intArrayHub).add("log", Boolean.getBoolean("graal.logNewArrayStub"));
     }
 
     /**
@@ -62,43 +62,40 @@
      * @param hub the hub of the object to be allocated
      * @param length the length of the array
      * @param intArrayHub the hub for {@code int[].class}
+     * @param log specifies if logging is enabled
      */
     @Snippet
-    private static Object newArray(@Parameter("hub") Word hub, @Parameter("length") int length, @ConstantParameter("intArrayHub") Word intArrayHub) {
+    private static Object newArray(
+                    @Parameter("hub") Word hub,
+                    @Parameter("length") int length,
+                    @ConstantParameter("intArrayHub") Word intArrayHub,
+                    @ConstantParameter("log") boolean log) {
         int layoutHelper = loadIntFromWord(hub, layoutHelperOffset());
         int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift()) & layoutHelperLog2ElementSizeMask();
         int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift()) & layoutHelperHeaderSizeMask();
         int elementKind = (layoutHelper >> layoutHelperElementTypeShift()) & layoutHelperElementTypeMask();
         int sizeInBytes = computeArrayAllocationSize(length, wordSize(), headerSize, log2ElementSize);
-        logf("newArray: element kind %d\n", elementKind);
-        logf("newArray: array length %d\n", length);
-        logf("newArray: array size %d\n", sizeInBytes);
-        logf("newArray: hub=%p\n", hub.toLong());
+        log(log, "newArray: element kind %d\n", elementKind);
+        log(log, "newArray: array length %d\n", length);
+        log(log, "newArray: array size %d\n", sizeInBytes);
+        log(log, "newArray: hub=%p\n", hub.toLong());
 
         // check that array length is small enough for fast path.
         if (length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) {
             Word memory;
-            if (refillTLAB(intArrayHub, Word.fromLong(tlabIntArrayMarkWord()), tlabAlignmentReserveInHeapWords() * wordSize())) {
+            if (refillTLAB(intArrayHub, Word.fromLong(tlabIntArrayMarkWord()), tlabAlignmentReserveInHeapWords() * wordSize(), log)) {
                 memory = allocate(sizeInBytes);
             } else {
-                logf("newArray: allocating directly in eden\n", 0L);
-                memory = edenAllocate(Word.fromInt(sizeInBytes));
+                log(log, "newArray: allocating directly in eden\n", 0L);
+                memory = edenAllocate(Word.fromInt(sizeInBytes), log);
             }
             if (memory != Word.zero()) {
-                logf("newArray: allocated new array at %p\n", memory.toLong());
+                log(log, "newArray: allocated new array at %p\n", memory.toLong());
                 formatArray(hub, sizeInBytes, length, headerSize, memory, Word.fromLong(arrayPrototypeMarkWord()), true);
                 return verifyOop(memory.toObject());
             }
         }
-        logf("newArray: calling new_array_slow", 0L);
+        log(log, "newArray: calling new_array_slow", 0L);
         return verifyOop(NewArraySlowStubCall.call(hub, length));
     }
-
-    private static final boolean LOGGING_ENABLED = Boolean.getBoolean("graal.logNewArrayStub");
-
-    private static void logf(String format, long value) {
-        if (LOGGING_ENABLED) {
-            Log.printf(format, value);
-        }
-    }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java	Mon Dec 17 11:12:25 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java	Mon Dec 17 11:29:06 2012 +0100
@@ -55,7 +55,7 @@
     protected void populateKey(Key key) {
         HotSpotResolvedObjectType intArrayType = (HotSpotResolvedObjectType) runtime.lookupJavaType(int[].class);
         Constant intArrayHub = intArrayType.klass();
-        key.add("intArrayHub", intArrayHub);
+        key.add("intArrayHub", intArrayHub).add("log", Boolean.getBoolean("graal.logNewInstanceStub"));
     }
 
     /**
@@ -65,20 +65,20 @@
      * @param intArrayHub the hub for {@code int[].class}
      */
     @Snippet
-    private static Object newInstance(@Parameter("hub") Word hub, @ConstantParameter("intArrayHub") Word intArrayHub) {
+    private static Object newInstance(
+                    @Parameter("hub") Word hub,
+                    @ConstantParameter("intArrayHub") Word intArrayHub,
+                    @ConstantParameter("log") boolean log) {
         int sizeInBytes = loadIntFromWord(hub, klassInstanceSizeOffset());
-        logf("newInstance: size %d\n", sizeInBytes);
         if (inlineContiguousAllocationSupported()) {
             if (loadIntFromWord(hub, klassStateOffset()) == klassStateFullyInitialized()) {
                 Word memory;
-                if (refillTLAB(intArrayHub, Word.fromLong(tlabIntArrayMarkWord()), tlabAlignmentReserveInHeapWords() * wordSize())) {
+                if (refillTLAB(intArrayHub, Word.fromLong(tlabIntArrayMarkWord()), tlabAlignmentReserveInHeapWords() * wordSize(), log)) {
                     memory = allocate(sizeInBytes);
                 } else {
-                    logf("newInstance: allocating directly in eden\n", 0L);
-                    memory = edenAllocate(Word.fromInt(sizeInBytes));
+                    memory = edenAllocate(Word.fromInt(sizeInBytes), log);
                 }
                 if (memory != Word.zero()) {
-                    logf("newInstance: allocated new object at %p\n", memory.toLong());
                     Word prototypeMarkWord = loadWordFromWord(hub, prototypeMarkWordOffset());
                     storeWord(memory, 0, markOffset(), prototypeMarkWord);
                     storeWord(memory, 0, hubOffset(), hub);
@@ -89,7 +89,6 @@
                 }
             }
         }
-        logf("newInstance: calling new_instance_slow", 0L);
         return verifyOop(NewInstanceSlowStubCall.call(hub));
     }
 
@@ -99,9 +98,10 @@
      * @param intArrayHub the hub for {@code int[].class}
      * @param intArrayMarkWord the mark word for the int array placed in the left over TLAB space
      * @param alignmentReserveInBytes the amount of extra bytes to reserve in a new TLAB
+     * @param log specifies if logging is enabled
      * @return whether or not a new TLAB was allocated
      */
-    static boolean refillTLAB(Word intArrayHub, Word intArrayMarkWord, int alignmentReserveInBytes) {
+    static boolean refillTLAB(Word intArrayHub, Word intArrayMarkWord, int alignmentReserveInBytes, boolean log) {
 
         Word thread = thread();
         Word top = loadWordFromWord(thread, threadTlabTopOffset());
@@ -110,24 +110,26 @@
         // calculate amount of free space
         Word tlabFreeSpaceInBytes = end.minus(top);
 
-        logf("refillTLAB: thread=%p\n", thread.toLong());
-        logf("refillTLAB: top=%p\n", top.toLong());
-        logf("refillTLAB: end=%p\n", end.toLong());
-        logf("refillTLAB: tlabFreeSpaceInBytes=%d\n", tlabFreeSpaceInBytes.toLong());
+        log(log, "refillTLAB: thread=%p\n", thread.toLong());
+        log(log, "refillTLAB: top=%p\n", top.toLong());
+        log(log, "refillTLAB: end=%p\n", end.toLong());
+        log(log, "refillTLAB: tlabFreeSpaceInBytes=%d\n", tlabFreeSpaceInBytes.toLong());
 
         // a DIV or SHR operations on Words would be handy here...
         Word tlabFreeSpaceInWords = Word.fromLong(tlabFreeSpaceInBytes.toLong() >>> log2WordSize());
 
         // Retain TLAB and allocate object in shared space if
         // the amount free in the TLAB is too large to discard.
-        if (tlabFreeSpaceInWords.belowOrEqual(loadWordFromWord(thread, tlabRefillWasteLimitOffset()))) {
-            logf("refillTLAB: discarding TLAB\n", 0L);
-
+        Word refillWasteLimit = loadWordFromWord(thread, tlabRefillWasteLimitOffset());
+        if (tlabFreeSpaceInWords.belowOrEqual(refillWasteLimit)) {
             if (tlabStats()) {
                 // increment number of refills
                 storeInt(thread, 0, tlabNumberOfRefillsOffset(), loadIntFromWord(thread, tlabNumberOfRefillsOffset()) + 1);
+                log(log, "thread: %p -- number_of_refills %d\n", thread.toLong(), loadIntFromWord(thread, tlabNumberOfRefillsOffset()));
                 // accumulate wastage
-                storeWord(thread, 0, tlabFastRefillWasteOffset(), loadWordFromWord(thread, tlabFastRefillWasteOffset()).plus(tlabFreeSpaceInWords));
+                Word wastage = loadWordFromWord(thread, tlabFastRefillWasteOffset()).plus(tlabFreeSpaceInWords);
+                log(log, "thread: %p -- accumulated wastage %d\n", thread.toLong(), wastage.toLong());
+                storeWord(thread, 0, tlabFastRefillWasteOffset(), wastage);
             }
 
             // if TLAB is currently allocated (top or end != null) then
@@ -137,9 +139,6 @@
                 // just like the HotSpot assembler stubs, assumes that tlabFreeSpaceInInts fits in an int
                 int tlabFreeSpaceInInts = (int) tlabFreeSpaceInBytes.toLong() >>> 2;
                 int length = ((alignmentReserveInBytes - headerSize) >>> 2) + tlabFreeSpaceInInts;
-                logf("refillTLAB: alignmentReserveInBytes %d\n", alignmentReserveInBytes);
-                logf("refillTLAB: headerSize %d\n", headerSize);
-                logf("refillTLAB: filler.length %d\n", length);
                 NewObjectSnippets.formatArray(intArrayHub, -1, length, headerSize, top, intArrayMarkWord, false);
 
                 Word allocated = loadWordFromWord(thread, threadAllocatedBytesOffset());
@@ -151,25 +150,22 @@
             Word tlabRefillSizeInWords = loadWordFromWord(thread, threadTlabSizeOffset());
             Word tlabRefillSizeInBytes = Word.fromLong(tlabRefillSizeInWords.toLong() * wordSize());
             // allocate new TLAB, address returned in top
-            top = edenAllocate(tlabRefillSizeInBytes);
+            top = edenAllocate(tlabRefillSizeInBytes, log);
             if (top != Word.zero()) {
                 storeWord(thread, 0, threadTlabStartOffset(), top);
                 storeWord(thread, 0, threadTlabTopOffset(), top);
 
                 end = top.plus(tlabRefillSizeInBytes.minus(alignmentReserveInBytes));
                 storeWord(thread, 0, threadTlabEndOffset(), end);
-                logf("refillTLAB: top'=%p\n", top.toLong());
-                logf("refillTLAB: start'=%p\n", top.toLong());
-                logf("refillTLAB: end'=%p\n", end.toLong());
                 return true;
             } else {
                 return false;
             }
         } else {
             // Retain TLAB
-            Word newRefillWasteLimit = loadWordFromWord(thread, tlabRefillWasteLimitOffset()).plus(tlabRefillWasteIncrement());
+            Word newRefillWasteLimit = refillWasteLimit.plus(tlabRefillWasteIncrement());
             storeWord(thread, 0, tlabRefillWasteLimitOffset(), newRefillWasteLimit);
-            logf("refillTLAB: retaining TLAB - newRefillWasteLimit=%p\n", newRefillWasteLimit.toLong());
+            log(log, "refillTLAB: retaining TLAB - newRefillWasteLimit=%p\n", newRefillWasteLimit.toLong());
 
             if (tlabStats()) {
                 storeInt(thread, 0, tlabSlowAllocationsOffset(), loadIntFromWord(thread, tlabSlowAllocationsOffset()) + 1);
@@ -183,43 +179,44 @@
      * Attempts to allocate a chunk of memory from Eden space.
      *
      * @param sizeInBytes the size of the chunk to allocate
+     * @param log specifies if logging is enabled
      * @return the allocated chunk or {@link Word#zero()} if allocation fails
      */
-    static Word edenAllocate(Word sizeInBytes) {
+    static Word edenAllocate(Word sizeInBytes, boolean log) {
         Word heapTopAddress = Word.fromLong(heapTopAddress());
         Word heapEndAddress = Word.fromLong(heapEndAddress());
-        logf("edenAllocate: heapTopAddress %p\n", heapTopAddress.toLong());
-        logf("edenAllocate: heapEndAddress %p\n", heapEndAddress.toLong());
 
         while (true) {
             Word heapTop = loadWordFromWord(heapTopAddress, 0);
             Word newHeapTop = heapTop.plus(sizeInBytes);
-            logf("edenAllocate: heapTop %p\n", heapTop.toLong());
-            logf("edenAllocate: newHeapTop %p\n", newHeapTop.toLong());
             if (newHeapTop.belowOrEqual(heapTop)) {
-                logf("edenAllocate: fail 1\n", 0L);
                 return Word.zero();
             }
 
             Word heapEnd = loadWordFromWord(heapEndAddress, 0);
-            logf("edenAllocate: heapEnd %p\n", heapEnd.toLong());
             if (newHeapTop.above(heapEnd)) {
-                logf("edenAllocate: fail 2\n", 0L);
                 return Word.zero();
             }
 
             if (compareAndSwap(heapTopAddress, 0, heapTop, newHeapTop) == heapTop) {
-                logf("edenAllocate: success %p\n", heapTop.toLong());
                 return heapTop;
             }
         }
     }
 
-    private static final boolean LOGGING_ENABLED = Boolean.getBoolean("graal.logNewInstanceStub");
-
-    private static void logf(String format, long value) {
-        if (LOGGING_ENABLED) {
+    static void log(boolean enabled, String format, long value) {
+        if (enabled) {
             Log.printf(format, value);
         }
     }
+    static void log(boolean enabled, String format, long v1, long v2) {
+        if (enabled) {
+            Log.printf(format, v1, v2);
+        }
+    }
+    static void log(boolean enabled, String format, long v1, long v2, long v3) {
+        if (enabled) {
+            Log.printf(format, v1, v2, v3);
+        }
+    }
 }