changeset 22597:99b7154e88c7

Avoid public native methods in CompilerToVM class.
author Roland Schatz <roland.schatz@oracle.com>
date Tue, 22 Sep 2015 17:13:02 +0200
parents 1cee82727437
children ed53e370f04c
files jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java src/share/vm/jvmci/jvmciCompilerToVM.cpp
diffstat 2 files changed, 81 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java	Tue Sep 22 16:11:39 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java	Tue Sep 22 17:13:02 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -314,7 +314,11 @@
      *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
      *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
      */
-    public native int installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, SpeculationLog speculationLog);
+    public int installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, SpeculationLog speculationLog) {
+        return installCodeImpl(target, compiledCode, code, speculationLog);
+    }
+
+    private native int installCodeImpl(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, SpeculationLog speculationLog);
 
     /**
      * Notifies the VM of statistics for a completed compilation.
@@ -328,13 +332,21 @@
      * @param timeUnitsPerSecond the granularity of the units for the {@code time} value
      * @param installedCode the nmethod installed as a result of the compilation
      */
-    public synchronized native void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethodImpl method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond,
+    public void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond, InstalledCode installedCode) {
+        notifyCompilationStatisticsImpl(id, (HotSpotResolvedJavaMethodImpl) method, osr, processedBytecodes, time, timeUnitsPerSecond, installedCode);
+    }
+
+    private synchronized native void notifyCompilationStatisticsImpl(int id, HotSpotResolvedJavaMethodImpl method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond,
                     InstalledCode installedCode);
 
     /**
      * Resets all compilation statistics.
      */
-    public native void resetCompilationStatistics();
+    public void resetCompilationStatistics() {
+        resetCompilationStatisticsImpl();
+    }
+
+    native void resetCompilationStatisticsImpl();
 
     /**
      * Initializes the fields of {@code config}.
@@ -378,7 +390,11 @@
      * @param address an address that may be called from any code in the code cache
      * @return -1 if {@code address == 0}
      */
-    public native long getMaxCallTargetOffset(long address);
+    public long getMaxCallTargetOffset(long address) {
+        return getMaxCallTargetOffsetImpl(address);
+    }
+
+    private native long getMaxCallTargetOffsetImpl(long address);
 
     /**
      * Gets a textual disassembly of {@code codeBlob}.
@@ -386,8 +402,12 @@
      * @return a non-zero length string containing a disassembly of {@code codeBlob} or null if
      *         {@code codeBlob} could not be disassembled for some reason
      */
+    public String disassembleCodeBlob(long codeBlob) {
+        return disassembleCodeBlobImpl(codeBlob);
+    }
+
     // The HotSpot disassembler seems not to be thread safe so it's better to synchronize its usage
-    public synchronized native String disassembleCodeBlob(long codeBlob);
+    private synchronized native String disassembleCodeBlobImpl(long codeBlob);
 
     /**
      * Gets a stack trace element for {@code method} at bytecode index {@code bci}.
@@ -465,12 +485,20 @@
      * Invalidates {@code installedCode} such that {@link InvalidInstalledCodeException} will be
      * raised the next time {@code installedCode} is executed.
      */
-    public native void invalidateInstalledCode(InstalledCode installedCode);
+    public void invalidateInstalledCode(InstalledCode installedCode) {
+        invalidateInstalledCodeImpl(installedCode);
+    }
+
+    private native void invalidateInstalledCodeImpl(InstalledCode installedCode);
 
     /**
      * Collects the current values of all JVMCI benchmark counters, summed up over all threads.
      */
-    public native long[] collectCounters();
+    public long[] collectCounters() {
+        return collectCountersImpl();
+    }
+
+    private native long[] collectCountersImpl();
 
     /**
      * Determines if {@code metaspaceMethodData} is mature.
@@ -500,7 +528,11 @@
      * @param methods the methods to look for, where {@code null} means that any frame is returned
      * @return the frame, or {@code null} if the end of the stack was reached during the search
      */
-    public native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, HotSpotResolvedJavaMethodImpl[] methods, int initialSkip);
+    public HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, ResolvedJavaMethod[] methods, int initialSkip) {
+        return getNextStackFrameImpl(frame, methods, initialSkip);
+    }
+
+    private native HotSpotStackFrameReference getNextStackFrameImpl(HotSpotStackFrameReference frame, ResolvedJavaMethod[] methods, int initialSkip);
 
     /**
      * Materializes all virtual objects within {@code stackFrame} updates its locals.
@@ -523,18 +555,30 @@
     /**
      * Determines if debug info should also be emitted at non-safepoint locations.
      */
-    public native boolean shouldDebugNonSafepoints();
+    public boolean shouldDebugNonSafepoints() {
+        return shouldDebugNonSafepointsImpl();
+    }
+
+    private native boolean shouldDebugNonSafepointsImpl();
 
     /**
      * Writes {@code length} bytes from {@code buf} starting at offset {@code offset} to the
      * HotSpot's log stream. No range checking is performed.
      */
-    public native void writeDebugOutput(byte[] bytes, int offset, int length);
+    public void writeDebugOutput(byte[] bytes, int offset, int length) {
+        writeDebugOutputImpl(bytes, offset, length);
+    }
+
+    private native void writeDebugOutputImpl(byte[] bytes, int offset, int length);
 
     /**
      * Flush HotSpot's log stream.
      */
-    public native void flushDebugOutput();
+    public void flushDebugOutput() {
+        flushDebugOutputImpl();
+    }
+
+    private native void flushDebugOutputImpl();
 
     /**
      * Read a value representing a metaspace Method* and return the
--- a/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Tue Sep 22 16:11:39 2015 +0200
+++ b/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Tue Sep 22 17:13:02 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -562,7 +562,7 @@
   return JNIHandles::make_local(THREAD, result);
 C2V_END
 
-C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv*, jobject, jlong addr))
+C2V_VMENTRY(jlong, getMaxCallTargetOffsetImpl, (JNIEnv*, jobject, jlong addr))
   address target_addr = (address) addr;
   if (target_addr != 0x0) {
     int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
@@ -579,7 +579,7 @@
   method->set_dont_inline(true);
 C2V_END
 
-C2V_VMENTRY(jint, installCode, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject installed_code, jobject speculation_log))
+C2V_VMENTRY(jint, installCodeImpl, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject installed_code, jobject speculation_log))
   ResourceMark rm;
   HandleMark hm;
   Handle target_handle = JNIHandles::resolve(target);
@@ -627,7 +627,7 @@
   return result;
 C2V_END
 
-C2V_VMENTRY(void, notifyCompilationStatistics, (JNIEnv *jniEnv, jobject, jint id, jobject hotspot_method, jboolean osr, jint processedBytecodes, jlong time, jlong timeUnitsPerSecond, jobject installed_code))
+C2V_VMENTRY(void, notifyCompilationStatisticsImpl, (JNIEnv *jniEnv, jobject, jint id, jobject hotspot_method, jboolean osr, jint processedBytecodes, jlong time, jlong timeUnitsPerSecond, jobject installed_code))
   CompilerStatistics* stats = JVMCICompiler::instance()->stats();
 
   elapsedTimer timer = elapsedTimer(time, timeUnitsPerSecond);
@@ -650,13 +650,13 @@
   }
 C2V_END
 
-C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv *jniEnv, jobject))
+C2V_VMENTRY(void, resetCompilationStatisticsImpl, (JNIEnv *jniEnv, jobject))
   CompilerStatistics* stats = JVMCICompiler::instance()->stats();
   stats->_standard.reset();
   stats->_osr.reset();
 C2V_END
 
-C2V_VMENTRY(jobject, disassembleCodeBlob, (JNIEnv *jniEnv, jobject, jlong codeBlob))
+C2V_VMENTRY(jobject, disassembleCodeBlobImpl, (JNIEnv *jniEnv, jobject, jlong codeBlob))
   ResourceMark rm;
   HandleMark hm;
 
@@ -810,7 +810,7 @@
 C2V_END
 
 
-C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv*, jobject, jobject hotspotInstalledCode))
+C2V_VMENTRY(void, invalidateInstalledCodeImpl, (JNIEnv*, jobject, jobject hotspotInstalledCode))
   jlong nativeMethod = InstalledCode::address(hotspotInstalledCode);
   nmethod* m = (nmethod*)nativeMethod;
   if (m != NULL && !m->is_not_entrant()) {
@@ -826,7 +826,7 @@
   return JNIHandles::make_local(THREAD, ret);
 C2V_END
 
-C2V_VMENTRY(jlongArray, collectCounters, (JNIEnv*, jobject))
+C2V_VMENTRY(jlongArray, collectCountersImpl, (JNIEnv*, jobject))
   typeArrayOop arrayOop = oopFactory::new_longArray(JVMCICounterSize, CHECK_NULL);
   JavaThread::collect_counters(arrayOop);
   return (jlongArray) JNIHandles::make_local(THREAD, arrayOop);
@@ -859,14 +859,15 @@
   objArrayOop methods_oop = (objArrayOop) JNIHandles::resolve(methods);
 
   for (int i = 0; i < methods_oop->length(); i++) {
-    if (CompilerToVM::asMethod(methods_oop->obj_at(i)) == method) {
+    oop resolved = methods_oop->obj_at(i);
+    if (resolved->is_a(HotSpotResolvedJavaMethodImpl::klass()) && CompilerToVM::asMethod(resolved) == method) {
       return true;
     }
   }
   return false;
 }
 
-C2V_VMENTRY(jobject, getNextStackFrame, (JNIEnv*, jobject compilerToVM, jobject hs_frame, jobjectArray methods, jint initialSkip))
+C2V_VMENTRY(jobject, getNextStackFrameImpl, (JNIEnv*, jobject compilerToVM, jobject hs_frame, jobjectArray methods, jint initialSkip))
   ResourceMark rm;
 
   if (!thread->has_last_Java_frame()) return NULL;
@@ -1017,7 +1018,7 @@
   cp_cache_entry->set_method_handle(cp, callInfo);
 C2V_END
 
-C2V_VMENTRY(jboolean, shouldDebugNonSafepoints, (JNIEnv*, jobject))
+C2V_VMENTRY(jboolean, shouldDebugNonSafepointsImpl, (JNIEnv*, jobject))
   //see compute_recording_non_safepoints in debugInfroRec.cpp
   if (JvmtiExport::should_post_compiled_method_load() && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
     return true;
@@ -1115,7 +1116,7 @@
   }
 C2V_END
 
-C2V_VMENTRY(void, writeDebugOutput, (JNIEnv*, jobject, jbyteArray bytes, jint offset, jint length))
+C2V_VMENTRY(void, writeDebugOutputImpl, (JNIEnv*, jobject, jbyteArray bytes, jint offset, jint length))
   while (length > 0) {
     jbyte* start = ((typeArrayOop) JNIHandles::resolve(bytes))->byte_at_addr(offset);
     tty->write((char*) start, MIN2(length, O_BUFLEN));
@@ -1124,7 +1125,7 @@
   }
 C2V_END
 
-C2V_VMENTRY(void, flushDebugOutput, (JNIEnv*, jobject))
+C2V_VMENTRY(void, flushDebugOutputImpl, (JNIEnv*, jobject))
   tty->flush();
 C2V_END
 
@@ -1198,33 +1199,33 @@
   {CC"getVtableIndexForInterfaceMethod",             CC"("HS_RESOLVED_KLASS HS_RESOLVED_METHOD")I",                                    FN_PTR(getVtableIndexForInterfaceMethod)},
   {CC"getClassInitializer",                          CC"("HS_RESOLVED_KLASS")"HS_RESOLVED_METHOD,                                      FN_PTR(getClassInitializer)},
   {CC"hasFinalizableSubclass",                       CC"("HS_RESOLVED_KLASS")Z",                                                       FN_PTR(hasFinalizableSubclass)},
-  {CC"getMaxCallTargetOffset",                       CC"(J)J",                                                                         FN_PTR(getMaxCallTargetOffset)},
+  {CC"getMaxCallTargetOffsetImpl",                   CC"(J)J",                                                                         FN_PTR(getMaxCallTargetOffsetImpl)},
   {CC"getResolvedJavaMethodAtSlot",                  CC"("CLASS"I)"HS_RESOLVED_METHOD,                                                 FN_PTR(getResolvedJavaMethodAtSlot)},
   {CC"getResolvedJavaMethod",                        CC"(Ljava/lang/Object;J)"HS_RESOLVED_METHOD,                                      FN_PTR(getResolvedJavaMethod)},
   {CC"getConstantPool",                              CC"(Ljava/lang/Object;J)"HS_CONSTANT_POOL,                                        FN_PTR(getConstantPool)},
   {CC"getResolvedJavaType",                          CC"(Ljava/lang/Object;JZ)"HS_RESOLVED_KLASS,                                      FN_PTR(getResolvedJavaType)},
   {CC"initializeConfiguration",                      CC"("HS_CONFIG")V",                                                               FN_PTR(initializeConfiguration)},
-  {CC"installCode",                                  CC"("TARGET_DESCRIPTION HS_COMPILED_CODE INSTALLED_CODE SPECULATION_LOG")I",      FN_PTR(installCode)},
-  {CC"notifyCompilationStatistics",                  CC"(I"HS_RESOLVED_METHOD"ZIJJ"INSTALLED_CODE")V",                                 FN_PTR(notifyCompilationStatistics)},
-  {CC"resetCompilationStatistics",                   CC"()V",                                                                          FN_PTR(resetCompilationStatistics)},
-  {CC"disassembleCodeBlob",                          CC"(J)"STRING,                                                                    FN_PTR(disassembleCodeBlob)},
+  {CC"installCodeImpl",                              CC"("TARGET_DESCRIPTION HS_COMPILED_CODE INSTALLED_CODE SPECULATION_LOG")I",      FN_PTR(installCodeImpl)},
+  {CC"notifyCompilationStatisticsImpl",              CC"(I"HS_RESOLVED_METHOD"ZIJJ"INSTALLED_CODE")V",                                 FN_PTR(notifyCompilationStatisticsImpl)},
+  {CC"resetCompilationStatisticsImpl",               CC"()V",                                                                          FN_PTR(resetCompilationStatisticsImpl)},
+  {CC"disassembleCodeBlobImpl",                      CC"(J)"STRING,                                                                    FN_PTR(disassembleCodeBlobImpl)},
   {CC"executeInstalledCode",                         CC"(["OBJECT INSTALLED_CODE")"OBJECT,                                             FN_PTR(executeInstalledCode)},
   {CC"getLineNumberTable",                           CC"("HS_RESOLVED_METHOD")[J",                                                     FN_PTR(getLineNumberTable)},
   {CC"getLocalVariableTableStart",                   CC"("HS_RESOLVED_METHOD")J",                                                      FN_PTR(getLocalVariableTableStart)},
   {CC"getLocalVariableTableLength",                  CC"("HS_RESOLVED_METHOD")I",                                                      FN_PTR(getLocalVariableTableLength)},
   {CC"reprofile",                                    CC"("HS_RESOLVED_METHOD")V",                                                      FN_PTR(reprofile)},
-  {CC"invalidateInstalledCode",                      CC"("INSTALLED_CODE")V",                                                          FN_PTR(invalidateInstalledCode)},
+  {CC"invalidateInstalledCodeImpl",                  CC"("INSTALLED_CODE")V",                                                          FN_PTR(invalidateInstalledCodeImpl)},
   {CC"readUncompressedOop",                          CC"(J)"OBJECT,                                                                    FN_PTR(readUncompressedOop)},
-  {CC"collectCounters",                              CC"()[J",                                                                         FN_PTR(collectCounters)},
+  {CC"collectCountersImpl",                          CC"()[J",                                                                         FN_PTR(collectCountersImpl)},
   {CC"allocateCompileId",                            CC"("HS_RESOLVED_METHOD"I)I",                                                     FN_PTR(allocateCompileId)},
   {CC"isMature",                                     CC"("METASPACE_METHOD_DATA")Z",                                                   FN_PTR(isMature)},
   {CC"hasCompiledCodeForOSR",                        CC"("HS_RESOLVED_METHOD"II)Z",                                                    FN_PTR(hasCompiledCodeForOSR)},
   {CC"getSymbol",                                    CC"(J)"STRING,                                                                    FN_PTR(getSymbol)},
-  {CC"getNextStackFrame",                            CC"("HS_STACK_FRAME_REF "["HS_RESOLVED_METHOD"I)"HS_STACK_FRAME_REF,              FN_PTR(getNextStackFrame)},
+  {CC"getNextStackFrameImpl",                        CC"("HS_STACK_FRAME_REF "["RESOLVED_METHOD"I)"HS_STACK_FRAME_REF,                 FN_PTR(getNextStackFrameImpl)},
   {CC"materializeVirtualObjects",                    CC"("HS_STACK_FRAME_REF"Z)V",                                                     FN_PTR(materializeVirtualObjects)},
-  {CC"shouldDebugNonSafepoints",                     CC"()Z",                                                                          FN_PTR(shouldDebugNonSafepoints)},
-  {CC"writeDebugOutput",                             CC"([BII)V",                                                                      FN_PTR(writeDebugOutput)},
-  {CC"flushDebugOutput",                             CC"()V",                                                                          FN_PTR(flushDebugOutput)},
+  {CC"shouldDebugNonSafepointsImpl",                 CC"()Z",                                                                          FN_PTR(shouldDebugNonSafepointsImpl)},
+  {CC"writeDebugOutputImpl",                         CC"([BII)V",                                                                      FN_PTR(writeDebugOutputImpl)},
+  {CC"flushDebugOutputImpl",                         CC"()V",                                                                          FN_PTR(flushDebugOutputImpl)},
   {CC"methodDataProfileDataSize",                    CC"(JI)I",                                                                        FN_PTR(methodDataProfileDataSize)},
 };