< prev index next >

src/share/vm/prims/whitebox.cpp

Print this page
rev 13541 : 8187045: [linux] Not all libraries in the VM are linked with -z,noexecstack.


  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 
  81 #define SIZE_T_MAX_VALUE ((size_t) -1)
  82 
  83 bool WhiteBox::_used = false;
  84 volatile bool WhiteBox::compilation_locked = false;
  85 
  86 class VM_WhiteBoxOperation : public VM_Operation {
  87  public:
  88   VM_WhiteBoxOperation()                         { }
  89   VMOp_Type type()                  const        { return VMOp_WhiteBoxOperation; }
  90   bool allow_nested_vm_operations() const        { return true; }
  91 };
  92 
  93 
  94 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
  95   return (jlong)(void*)JNIHandles::resolve(obj);
  96 WB_END
  97 
  98 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o))
  99   return heapOopSize;


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


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