< prev index next >

src/hotspot/share/prims/whitebox.cpp

Print this page
rev 47248 : 8187045: [linux] Not all libraries in the VM are linked with -z,noexecstack
Reviewed-by: ihse, dholmes


  56 #include "runtime/thread.hpp"
  57 #include "runtime/vm_version.hpp"
  58 #include "utilities/align.hpp"
  59 #include "utilities/debug.hpp"
  60 #include "utilities/exceptions.hpp"
  61 #include "utilities/macros.hpp"
  62 #if INCLUDE_ALL_GCS
  63 #include "gc/g1/concurrentMarkThread.hpp"
  64 #include "gc/g1/g1CollectedHeap.inline.hpp"
  65 #include "gc/g1/g1ConcurrentMark.hpp"
  66 #include "gc/g1/heapRegionRemSet.hpp"
  67 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
  68 #include "gc/parallel/adjoiningGenerations.hpp"
  69 #endif // INCLUDE_ALL_GCS
  70 #if INCLUDE_NMT
  71 #include "services/mallocSiteTable.hpp"
  72 #include "services/memTracker.hpp"
  73 #include "utilities/nativeCallStack.hpp"
  74 #endif // INCLUDE_NMT
  75 



  76 
  77 #define SIZE_T_MAX_VALUE ((size_t) -1)
  78 
  79 bool WhiteBox::_used = false;
  80 volatile bool WhiteBox::compilation_locked = false;
  81 
  82 class VM_WhiteBoxOperation : public VM_Operation {
  83  public:
  84   VM_WhiteBoxOperation()                         { }
  85   VMOp_Type type()                  const        { return VMOp_WhiteBoxOperation; }
  86   bool allow_nested_vm_operations() const        { return true; }
  87 };
  88 
  89 
  90 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
  91   return (jlong)(void*)JNIHandles::resolve(obj);
  92 WB_END
  93 
  94 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o))
  95   return heapOopSize;


1806   ThreadToNativeFromVM ttnfv(thread);
1807   const char* dir = env->GetStringUTFChars(compDirect, NULL);
1808   CHECK_JNI_EXCEPTION_(env, 0);
1809   int ret;
1810   {
1811     ThreadInVMfromNative ttvfn(thread); // back to VM
1812     ret = DirectivesParser::parse_string(dir, tty);
1813   }
1814   env->ReleaseStringUTFChars(compDirect, dir);
1815   // -1 for error parsing directive. Return 0 as number of directives added.
1816   if (ret == -1) {
1817     ret = 0;
1818   }
1819   return (jint) ret;
1820 WB_END
1821 
1822 WB_ENTRY(void, WB_RemoveCompilerDirective(JNIEnv* env, jobject o, jint count))
1823   DirectivesStack::pop(count);
1824 WB_END
1825 














1826 #define CC (char*)
1827 
1828 static JNINativeMethod methods[] = {
1829   {CC"getObjectAddress0",                CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
1830   {CC"getObjectSize0",                   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
1831   {CC"isObjectInOldGen0",                CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
1832   {CC"getHeapOopSize",                   CC"()I",                   (void*)&WB_GetHeapOopSize    },
1833   {CC"getVMPageSize",                    CC"()I",                   (void*)&WB_GetVMPageSize     },
1834   {CC"getVMAllocationGranularity",       CC"()J",                   (void*)&WB_GetVMAllocationGranularity },
1835   {CC"getVMLargePageSize",               CC"()J",                   (void*)&WB_GetVMLargePageSize},
1836   {CC"getHeapSpaceAlignment",            CC"()J",                   (void*)&WB_GetHeapSpaceAlignment},
1837   {CC"getHeapAlignment",                 CC"()J",                   (void*)&WB_GetHeapAlignment},
1838   {CC"isClassAlive0",                    CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive      },
1839   {CC"parseCommandLine0",
1840       CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1841       (void*) &WB_ParseCommandLine
1842   },
1843   {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1844                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
1845   {CC"addToSystemClassLoaderSearch0",    CC"(Ljava/lang/String;)V",


2010   {CC"getMethodStringOption",
2011       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2012                                                       (void*)&WB_GetMethodStringOption},
2013   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
2014   {CC"isSharedClass",      CC"(Ljava/lang/Class;)Z",  (void*)&WB_IsSharedClass },
2015   {CC"areSharedStringsIgnored",           CC"()Z",    (void*)&WB_AreSharedStringsIgnored },
2016   {CC"getResolvedReferences", CC"(Ljava/lang/Class;)Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
2017   {CC"isCDSIncludedInVmBuild",            CC"()Z",    (void*)&WB_IsCDSIncludedInVmBuild },
2018   {CC"clearInlineCaches0",  CC"(Z)V",                 (void*)&WB_ClearInlineCaches },
2019   {CC"addCompilerDirective",    CC"(Ljava/lang/String;)I",
2020                                                       (void*)&WB_AddCompilerDirective },
2021   {CC"removeCompilerDirective",   CC"(I)V",             (void*)&WB_RemoveCompilerDirective },
2022   {CC"currentGC",                 CC"()I",            (void*)&WB_CurrentGC},
2023   {CC"allSupportedGC",            CC"()I",            (void*)&WB_AllSupportedGC},
2024   {CC"gcSelectedByErgo",          CC"()Z",            (void*)&WB_GCSelectedByErgo},
2025   {CC"supportsConcurrentGCPhaseControl", CC"()Z",     (void*)&WB_SupportsConcurrentGCPhaseControl},
2026   {CC"getConcurrentGCPhases",     CC"()[Ljava/lang/String;",
2027                                                       (void*)&WB_GetConcurrentGCPhases},
2028   {CC"requestConcurrentGCPhase0", CC"(Ljava/lang/String;)Z",
2029                                                       (void*)&WB_RequestConcurrentGCPhase},


2030 };
2031 
2032 #undef CC
2033 
2034 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
2035   {
2036     if (WhiteBoxAPI) {
2037       // Make sure that wbclass is loaded by the null classloader
2038       InstanceKlass* ik = InstanceKlass::cast(JNIHandles::resolve(wbclass)->klass());
2039       Handle loader(THREAD, ik->class_loader());
2040       if (loader.is_null()) {
2041         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
2042         WhiteBox::register_extended(env, wbclass, thread);
2043         WhiteBox::set_used();
2044       }
2045     }
2046   }
2047 JVM_END


  56 #include "runtime/thread.hpp"
  57 #include "runtime/vm_version.hpp"
  58 #include "utilities/align.hpp"
  59 #include "utilities/debug.hpp"
  60 #include "utilities/exceptions.hpp"
  61 #include "utilities/macros.hpp"
  62 #if INCLUDE_ALL_GCS
  63 #include "gc/g1/concurrentMarkThread.hpp"
  64 #include "gc/g1/g1CollectedHeap.inline.hpp"
  65 #include "gc/g1/g1ConcurrentMark.hpp"
  66 #include "gc/g1/heapRegionRemSet.hpp"
  67 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
  68 #include "gc/parallel/adjoiningGenerations.hpp"
  69 #endif // INCLUDE_ALL_GCS
  70 #if INCLUDE_NMT
  71 #include "services/mallocSiteTable.hpp"
  72 #include "services/memTracker.hpp"
  73 #include "utilities/nativeCallStack.hpp"
  74 #endif // INCLUDE_NMT
  75 
  76 #ifdef LINUX
  77 #include "utilities/elfFile.hpp"
  78 #endif
  79 
  80 #define SIZE_T_MAX_VALUE ((size_t) -1)
  81 
  82 bool WhiteBox::_used = false;
  83 volatile bool WhiteBox::compilation_locked = false;
  84 
  85 class VM_WhiteBoxOperation : public VM_Operation {
  86  public:
  87   VM_WhiteBoxOperation()                         { }
  88   VMOp_Type type()                  const        { return VMOp_WhiteBoxOperation; }
  89   bool allow_nested_vm_operations() const        { return true; }
  90 };
  91 
  92 
  93 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
  94   return (jlong)(void*)JNIHandles::resolve(obj);
  95 WB_END
  96 
  97 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o))
  98   return heapOopSize;


1809   ThreadToNativeFromVM ttnfv(thread);
1810   const char* dir = env->GetStringUTFChars(compDirect, NULL);
1811   CHECK_JNI_EXCEPTION_(env, 0);
1812   int ret;
1813   {
1814     ThreadInVMfromNative ttvfn(thread); // back to VM
1815     ret = DirectivesParser::parse_string(dir, tty);
1816   }
1817   env->ReleaseStringUTFChars(compDirect, dir);
1818   // -1 for error parsing directive. Return 0 as number of directives added.
1819   if (ret == -1) {
1820     ret = 0;
1821   }
1822   return (jint) ret;
1823 WB_END
1824 
1825 WB_ENTRY(void, WB_RemoveCompilerDirective(JNIEnv* env, jobject o, jint count))
1826   DirectivesStack::pop(count);
1827 WB_END
1828 
1829 // Checks that the library libfile has the noexecstack bit set.
1830 WB_ENTRY(jboolean, WB_CheckLibSpecifiesNoexecstack(JNIEnv* env, jobject o, jstring libfile))
1831   jboolean ret = false;
1832 #ifdef LINUX
1833   // Can't be in VM when we call JNI.
1834   ThreadToNativeFromVM ttnfv(thread);
1835   const char* lf = env->GetStringUTFChars(libfile, NULL);
1836   CHECK_JNI_EXCEPTION_(env, 0);
1837   ret = (jboolean) ElfFile::specifies_noexecstack(lf);
1838   env->ReleaseStringUTFChars(libfile, lf);
1839 #endif
1840   return ret;
1841 WB_END
1842 
1843 #define CC (char*)
1844 
1845 static JNINativeMethod methods[] = {
1846   {CC"getObjectAddress0",                CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
1847   {CC"getObjectSize0",                   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
1848   {CC"isObjectInOldGen0",                CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
1849   {CC"getHeapOopSize",                   CC"()I",                   (void*)&WB_GetHeapOopSize    },
1850   {CC"getVMPageSize",                    CC"()I",                   (void*)&WB_GetVMPageSize     },
1851   {CC"getVMAllocationGranularity",       CC"()J",                   (void*)&WB_GetVMAllocationGranularity },
1852   {CC"getVMLargePageSize",               CC"()J",                   (void*)&WB_GetVMLargePageSize},
1853   {CC"getHeapSpaceAlignment",            CC"()J",                   (void*)&WB_GetHeapSpaceAlignment},
1854   {CC"getHeapAlignment",                 CC"()J",                   (void*)&WB_GetHeapAlignment},
1855   {CC"isClassAlive0",                    CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive      },
1856   {CC"parseCommandLine0",
1857       CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1858       (void*) &WB_ParseCommandLine
1859   },
1860   {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1861                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
1862   {CC"addToSystemClassLoaderSearch0",    CC"(Ljava/lang/String;)V",


2027   {CC"getMethodStringOption",
2028       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2029                                                       (void*)&WB_GetMethodStringOption},
2030   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
2031   {CC"isSharedClass",      CC"(Ljava/lang/Class;)Z",  (void*)&WB_IsSharedClass },
2032   {CC"areSharedStringsIgnored",           CC"()Z",    (void*)&WB_AreSharedStringsIgnored },
2033   {CC"getResolvedReferences", CC"(Ljava/lang/Class;)Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
2034   {CC"isCDSIncludedInVmBuild",            CC"()Z",    (void*)&WB_IsCDSIncludedInVmBuild },
2035   {CC"clearInlineCaches0",  CC"(Z)V",                 (void*)&WB_ClearInlineCaches },
2036   {CC"addCompilerDirective",    CC"(Ljava/lang/String;)I",
2037                                                       (void*)&WB_AddCompilerDirective },
2038   {CC"removeCompilerDirective",   CC"(I)V",             (void*)&WB_RemoveCompilerDirective },
2039   {CC"currentGC",                 CC"()I",            (void*)&WB_CurrentGC},
2040   {CC"allSupportedGC",            CC"()I",            (void*)&WB_AllSupportedGC},
2041   {CC"gcSelectedByErgo",          CC"()Z",            (void*)&WB_GCSelectedByErgo},
2042   {CC"supportsConcurrentGCPhaseControl", CC"()Z",     (void*)&WB_SupportsConcurrentGCPhaseControl},
2043   {CC"getConcurrentGCPhases",     CC"()[Ljava/lang/String;",
2044                                                       (void*)&WB_GetConcurrentGCPhases},
2045   {CC"requestConcurrentGCPhase0", CC"(Ljava/lang/String;)Z",
2046                                                       (void*)&WB_RequestConcurrentGCPhase},
2047   {CC"checkLibSpecifiesNoexecstack", CC"(Ljava/lang/String;)Z",
2048                                                       (void*)&WB_CheckLibSpecifiesNoexecstack},
2049 };
2050 
2051 #undef CC
2052 
2053 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
2054   {
2055     if (WhiteBoxAPI) {
2056       // Make sure that wbclass is loaded by the null classloader
2057       InstanceKlass* ik = InstanceKlass::cast(JNIHandles::resolve(wbclass)->klass());
2058       Handle loader(THREAD, ik->class_loader());
2059       if (loader.is_null()) {
2060         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
2061         WhiteBox::register_extended(env, wbclass, thread);
2062         WhiteBox::set_used();
2063       }
2064     }
2065   }
2066 JVM_END
< prev index next >