changeset 12792:be9c3426daad

pass thread register into allocation stubs instead of getting it from the host provider
author Doug Simon <doug.simon@oracle.com>
date Wed, 20 Nov 2013 13:58:38 +0100
parents 1cc0a907e1dd
children af7fb87fc62e
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java 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 3 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java	Wed Nov 20 13:57:25 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java	Wed Nov 20 13:58:38 2013 +0100
@@ -476,6 +476,12 @@
         return loadWordFromObjectIntrinsic(object, offset, getWordKind(), LocationIdentity.ANY_LOCATION);
     }
 
+    /**
+     * Reads the value of a given register.
+     * 
+     * @param register a register which must not be available to the register allocator
+     * @return the value of {@code register} as a word
+     */
     public static Word registerAsWord(@ConstantNodeParameter Register register) {
         return registerAsWord(register, true, false);
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java	Wed Nov 20 13:57:25 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java	Wed Nov 20 13:58:38 2013 +0100
@@ -70,6 +70,7 @@
         args.add("hub", null);
         args.add("length", null);
         args.addConst("intArrayHub", intArrayHub);
+        args.addConst("threadRegister", providers.getRegisters().getThreadRegister());
         return args;
     }
 
@@ -87,7 +88,7 @@
      * @param intArrayHub the hub for {@code int[].class}
      */
     @Snippet
-    private static Object newArray(Word hub, int length, @ConstantParameter Word intArrayHub) {
+    private static Object newArray(Word hub, int length, @ConstantParameter Word intArrayHub, @ConstantParameter Register threadRegister) {
         int layoutHelper = hub.readInt(layoutHelperOffset(), LocationIdentity.FINAL_LOCATION);
         int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift()) & layoutHelperLog2ElementSizeMask();
         int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift()) & layoutHelperHeaderSizeMask();
@@ -102,7 +103,7 @@
 
         // check that array length is small enough for fast path.
         if (length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) {
-            Word memory = refillAllocate(intArrayHub, sizeInBytes, logging());
+            Word memory = refillAllocate(threadRegister, intArrayHub, sizeInBytes, logging());
             if (memory.notEqual(0)) {
                 if (logging()) {
                     printf("newArray: allocated new array at %p\n", memory.rawValue());
@@ -114,9 +115,9 @@
             printf("newArray: calling new_array_c\n");
         }
 
-        newArrayC(NEW_ARRAY_C, thread(), hub, length);
+        newArrayC(NEW_ARRAY_C, registerAsWord(threadRegister), hub, length);
         handlePendingException(true);
-        return verifyObject(getAndClearObjectResult(thread()));
+        return verifyObject(getAndClearObjectResult(registerAsWord(threadRegister)));
     }
 
     public static final ForeignCallDescriptor NEW_ARRAY_C = descriptorFor(NewArrayStub.class, "newArrayC");
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java	Wed Nov 20 13:57:25 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java	Wed Nov 20 13:58:38 2013 +0100
@@ -70,11 +70,11 @@
         Arguments args = new Arguments(stub, GuardsStage.FLOATING_GUARDS);
         args.add("hub", null);
         args.addConst("intArrayHub", intArrayHub);
+        args.addConst("threadRegister", providers.getRegisters().getThreadRegister());
         return args;
     }
 
-    private static Word allocate(int size) {
-        Word thread = thread();
+    private static Word allocate(Word thread, int size) {
         Word top = readTlabTop(thread);
         Word end = readTlabEnd(thread);
         Word newTop = top.add(size);
@@ -102,11 +102,11 @@
      * @param intArrayHub the hub for {@code int[].class}
      */
     @Snippet
-    private static Object newInstance(Word hub, @ConstantParameter Word intArrayHub) {
+    private static Object newInstance(Word hub, @ConstantParameter Word intArrayHub, @ConstantParameter Register threadRegister) {
         int sizeInBytes = hub.readInt(klassInstanceSizeOffset(), LocationIdentity.FINAL_LOCATION);
         if (!forceSlowPath() && inlineContiguousAllocationSupported()) {
             if (hub.readByte(klassStateOffset(), CLASS_STATE_LOCATION) == klassStateFullyInitialized()) {
-                Word memory = refillAllocate(intArrayHub, sizeInBytes, logging());
+                Word memory = refillAllocate(threadRegister, intArrayHub, sizeInBytes, logging());
                 if (memory.notEqual(0)) {
                     Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset(), PROTOTYPE_MARK_WORD_LOCATION);
                     initializeObjectHeader(memory, prototypeMarkWord, hub);
@@ -122,9 +122,9 @@
             printf("newInstance: calling new_instance_c\n");
         }
 
-        newInstanceC(NEW_INSTANCE_C, thread(), hub);
+        newInstanceC(NEW_INSTANCE_C, registerAsWord(threadRegister), hub);
         handlePendingException(true);
-        return verifyObject(getAndClearObjectResult(thread()));
+        return verifyObject(getAndClearObjectResult(registerAsWord(threadRegister)));
     }
 
     /**
@@ -133,10 +133,11 @@
      * @param intArrayHub the hub for {@code int[].class}
      * @param sizeInBytes the size of the allocation
      * @param log specifies if logging is enabled
+     * 
      * @return the newly allocated, uninitialized chunk of memory, or {@link Word#zero()} if the
      *         operation was unsuccessful
      */
-    static Word refillAllocate(Word intArrayHub, int sizeInBytes, boolean log) {
+    static Word refillAllocate(Register threadRegister, Word intArrayHub, int sizeInBytes, boolean log) {
         // If G1 is enabled, the "eden" allocation space is not the same always
         // and therefore we have to go to slowpath to allocate a new TLAB.
         if (useG1GC()) {
@@ -148,7 +149,7 @@
         Word intArrayMarkWord = Word.unsigned(tlabIntArrayMarkWord());
         int alignmentReserveInBytes = tlabAlignmentReserveInHeapWords() * wordSize();
 
-        Word thread = thread();
+        Word thread = registerAsWord(threadRegister);
         Word top = readTlabTop(thread);
         Word end = readTlabEnd(thread);
 
@@ -206,7 +207,7 @@
                 end = top.add(tlabRefillSizeInBytes.subtract(alignmentReserveInBytes));
                 initializeTlab(thread, top, end);
 
-                return NewInstanceStub.allocate(sizeInBytes);
+                return NewInstanceStub.allocate(thread, sizeInBytes);
             } else {
                 return Word.zero();
             }