# HG changeset patch # User bharadwaj # Date 1403630638 14400 # Node ID 0a7e9347f8d09e47652d8a0812607d5a588a626b # Parent da146f137cf7e512671ece25bd384c0c6b586590 Add an ability to specify the signature of a C/C++ foreign function in HotSpotVMConfig and get the full symbol string; add a couple of convenience getters and setters for stubs with foreign call linkage. diff -r da146f137cf7 -r 0a7e9347f8d0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java Tue Jun 24 09:35:18 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java Tue Jun 24 13:23:58 2014 -0400 @@ -269,4 +269,12 @@ public boolean needsJavaFrameAnchor() { return canDeoptimize() || transition == Transition.LEAF_SP; } + + public CompilationResult getStubCompilationResult(final Backend backend) { + return stub.getCompilationResult(backend); + } + + public Stub getStub() { + return stub; + } } diff -r da146f137cf7 -r 0a7e9347f8d0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Tue Jun 24 09:35:18 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Tue Jun 24 13:23:58 2014 -0400 @@ -1424,9 +1424,9 @@ @HotSpotVMValue(expression = "GraalRuntime::dynamic_new_array", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dynamicNewArrayAddress; @HotSpotVMValue(expression = "GraalRuntime::dynamic_new_instance", get = HotSpotVMValue.Type.ADDRESS) @Stable public long dynamicNewInstanceAddress; @HotSpotVMValue(expression = "GraalRuntime::thread_is_interrupted", get = HotSpotVMValue.Type.ADDRESS) @Stable public long threadIsInterruptedAddress; - @HotSpotVMValue(expression = "GraalRuntime::vm_message", get = HotSpotVMValue.Type.ADDRESS) @Stable public long vmMessageAddress; + @HotSpotVMValue(expression = "GraalRuntime::vm_message", signature = "(unsigned char, long, long, long, long)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long vmMessageAddress; @HotSpotVMValue(expression = "GraalRuntime::identity_hash_code", get = HotSpotVMValue.Type.ADDRESS) @Stable public long identityHashCodeAddress; - @HotSpotVMValue(expression = "GraalRuntime::exception_handler_for_pc", get = HotSpotVMValue.Type.ADDRESS) @Stable public long exceptionHandlerForPcAddress; + @HotSpotVMValue(expression = "GraalRuntime::exception_handler_for_pc", signature = "(JavaThread*)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long exceptionHandlerForPcAddress; @HotSpotVMValue(expression = "GraalRuntime::monitorenter", get = HotSpotVMValue.Type.ADDRESS) @Stable public long monitorenterAddress; @HotSpotVMValue(expression = "GraalRuntime::monitorexit", get = HotSpotVMValue.Type.ADDRESS) @Stable public long monitorexitAddress; @HotSpotVMValue(expression = "GraalRuntime::create_null_exception", get = HotSpotVMValue.Type.ADDRESS) @Stable public long createNullPointerExceptionAddress; @@ -1452,9 +1452,9 @@ @HotSpotVMValue(expression = "(jint) GraalCounterSize") @Stable public int graalCountersSize; - @HotSpotVMValue(expression = "Deoptimization::fetch_unroll_info", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationFetchUnrollInfo; + @HotSpotVMValue(expression = "Deoptimization::fetch_unroll_info", signature = "(JavaThread*)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationFetchUnrollInfo; @HotSpotVMValue(expression = "Deoptimization::uncommon_trap", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationUncommonTrap; - @HotSpotVMValue(expression = "Deoptimization::unpack_frames", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationUnpackFrames; + @HotSpotVMValue(expression = "Deoptimization::unpack_frames", signature = "(JavaThread*, int)", get = HotSpotVMValue.Type.ADDRESS) @Stable public long deoptimizationUnpackFrames; @HotSpotVMConstant(name = "Deoptimization::Reason_none") @Stable public int deoptReasonNone; @HotSpotVMConstant(name = "Deoptimization::Reason_null_check") @Stable public int deoptReasonNullCheck; @@ -1599,4 +1599,35 @@ } } } + + /** + * Returns the name of the C/C++ function that is associated (via HotSpotVMValue annotation) + * with the HotSpotVMConfig object's field containing {@code foreignCalltargetAddress}; returns + * null if no field holds the provided address. + * + * @param foreignCallTargetAddress address of foreign call target + * @return C/C++ symbol name or null + */ + public String getCSymbol(long foreignCallTargetAddress) { + for (Field f : HotSpotVMConfig.class.getDeclaredFields()) { + if (f.isAnnotationPresent(HotSpotVMValue.class)) { + HotSpotVMValue annotation = f.getAnnotation(HotSpotVMValue.class); + + if (annotation.get() == HotSpotVMValue.Type.ADDRESS) { + try { + if (foreignCallTargetAddress == f.getLong(this)) { + return (annotation.expression() + annotation.signature()); + } + } catch (IllegalArgumentException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + } + return null; + } } diff -r da146f137cf7 -r 0a7e9347f8d0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostForeignCallsProvider.java Tue Jun 24 09:35:18 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostForeignCallsProvider.java Tue Jun 24 13:23:58 2014 -0400 @@ -175,4 +175,9 @@ registerArrayCopy(Kind.Object, c.oopArraycopy, c.oopAlignedArraycopy, c.oopDisjointArraycopy, c.oopAlignedDisjointArraycopy); registerArrayCopy(Kind.Object, c.oopArraycopyUninit, c.oopAlignedArraycopyUninit, c.oopDisjointArraycopyUninit, c.oopAlignedDisjointArraycopyUninit, true); } + + public HotSpotForeignCallLinkage getForeignCall(ForeignCallDescriptor descriptor) { + assert foreignCalls != null : descriptor; + return foreignCalls.get(descriptor); + } } diff -r da146f137cf7 -r 0a7e9347f8d0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Tue Jun 24 09:35:18 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Tue Jun 24 13:23:58 2014 -0400 @@ -64,6 +64,11 @@ protected InstalledCode code; /** + * Compilation result from which {@link #code} was created. + */ + protected CompilationResult compResult; + + /** * The registers destroyed by this stub. */ private Set destroyedRegisters; @@ -152,7 +157,7 @@ CallingConvention incomingCc = linkage.getIncomingCallingConvention(); TargetDescription target = codeCache.getTarget(); - final CompilationResult compResult = new CompilationResult(); + compResult = new CompilationResult(); try (Scope s0 = Debug.scope("StubCompilation", graph, providers.getCodeCache())) { Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); SchedulePhase schedule = emitFrontEnd(providers, target, graph, assumptions, null, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, @@ -182,6 +187,18 @@ } assert code != null : "error installing stub " + this; } + return code; } + + /** + * Gets the compilation result for this stub, compiling it first if necessary, and installing it + * in code. + */ + public synchronized CompilationResult getCompilationResult(final Backend backend) { + if (code == null) { + getCode(backend); + } + return compResult; + } } diff -r da146f137cf7 -r 0a7e9347f8d0 graal/com.oracle.graal.hotspotvmconfig/src/com/oracle/graal/hotspotvmconfig/HotSpotVMValue.java --- a/graal/com.oracle.graal.hotspotvmconfig/src/com/oracle/graal/hotspotvmconfig/HotSpotVMValue.java Tue Jun 24 09:35:18 2014 -0700 +++ b/graal/com.oracle.graal.hotspotvmconfig/src/com/oracle/graal/hotspotvmconfig/HotSpotVMValue.java Tue Jun 24 13:23:58 2014 -0400 @@ -45,6 +45,13 @@ VALUE } + /** + * If {@link #expression} is a C++ function name, {@link #signature} represents the signature of + * the function. + * + */ + String signature() default ""; + Type get() default Type.VALUE; /**