< prev index next >

src/share/vm/prims/whitebox.cpp

Print this page

        

*** 38,47 **** --- 38,48 ---- #include "runtime/arguments.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/os.hpp" #include "utilities/array.hpp" + #include "utilities/align.hpp" #include "utilities/debug.hpp" #include "utilities/macros.hpp" #include "utilities/exceptions.hpp" #if INCLUDE_ALL_GCS
*** 566,582 **** bool result = mh->force_inline(); mh->set_force_inline(value == JNI_TRUE); return result; WB_END WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci)) jmethodID jmid = reflected_method_to_jmid(thread, env, method); CHECK_JNI_EXCEPTION_(env, JNI_FALSE); ! methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); ! nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD); ! MutexLockerEx mu(Compile_lock); ! return (mh->queued_for_compilation() || nm != NULL); WB_END class VM_WhiteBoxOperation : public VM_Operation { public: VM_WhiteBoxOperation() { } --- 567,623 ---- bool result = mh->force_inline(); mh->set_force_inline(value == JNI_TRUE); return result; WB_END + bool WhiteBox::compile_method(Method* method, int comp_level, int bci, Thread* THREAD) { + // Screen for unavailable/bad comp level or null method + AbstractCompiler* comp = CompileBroker::compiler(comp_level); + if (method == NULL) { + tty->print_cr("WB error: request to compile NULL method"); + return false; + } + if (comp_level > MIN2((CompLevel) TieredStopAtLevel, CompLevel_highest_tier)) { + tty->print_cr("WB error: invalid compilation level %d", comp_level); + return false; + } + if (comp == NULL) { + tty->print_cr("WB error: no compiler for requested compilation level %d", comp_level); + return false; + } + + methodHandle mh(THREAD, method); + + // Compile method and check result + nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "Whitebox", THREAD); + MutexLocker mu(Compile_lock); + bool is_queued = mh->queued_for_compilation(); + if (is_queued || nm != NULL) { + return true; + } + tty->print("WB error: failed to compile at level %d method ", comp_level); + mh->print_short_name(tty); + tty->cr(); + if (is_queued) { + tty->print_cr("WB error: blocking compilation is still in queue!"); + } + return false; + } + WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci)) jmethodID jmid = reflected_method_to_jmid(thread, env, method); CHECK_JNI_EXCEPTION_(env, JNI_FALSE); ! return WhiteBox::compile_method(Method::checked_resolve_jmethod_id(jmid), comp_level, bci, THREAD); ! WB_END ! ! WB_ENTRY(jboolean, WB_EnqueueInitializerForCompilation(JNIEnv* env, jobject o, jclass klass, jint comp_level)) ! InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); ! Method* clinit = ik->class_initializer(); ! if (clinit == NULL) { ! return false; ! } ! return WhiteBox::compile_method(clinit, comp_level, InvocationEntryBci, THREAD); WB_END class VM_WhiteBoxOperation : public VM_Operation { public: VM_WhiteBoxOperation() { }
*** 651,667 **** icnt->set(InvocationCounter::wait_for_compile, Tier4MinInvocationThreshold + 1); bcnt->set(InvocationCounter::wait_for_compile, Tier4CompileThreshold + 1); WB_END template <typename T> ! static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAt)(const char*, T*)) { if (name == NULL) { return false; } ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI const char* flag_name = env->GetStringUTFChars(name, NULL); ! bool result = (*TAt)(flag_name, value); env->ReleaseStringUTFChars(name, flag_name); return result; } template <typename T> --- 692,708 ---- icnt->set(InvocationCounter::wait_for_compile, Tier4MinInvocationThreshold + 1); bcnt->set(InvocationCounter::wait_for_compile, Tier4CompileThreshold + 1); WB_END template <typename T> ! static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAt)(const char*, T*, bool, bool)) { if (name == NULL) { return false; } ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI const char* flag_name = env->GetStringUTFChars(name, NULL); ! bool result = (*TAt)(flag_name, value, true, true); env->ReleaseStringUTFChars(name, flag_name); return result; } template <typename T>
*** 802,812 **** if (needFree) { FREE_C_HEAP_ARRAY(char, ccstrResult, mtInternal); } WB_END - WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) ResourceMark rm(THREAD); int len; jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false); return (StringTable::lookup(name, len) != NULL); --- 843,852 ----
*** 849,858 **** --- 889,939 ---- CHECK_JNI_EXCEPTION_(env, NULL); return features_string; WB_END + int WhiteBox::get_blob_type(const CodeBlob* code) { + guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); + return CodeBlobType::All;; + } + + struct CodeBlobStub { + CodeBlobStub(const CodeBlob* blob) : + name(os::strdup(blob->name())), + size(blob->size()), + blob_type(WhiteBox::get_blob_type(blob)), + address((jlong) blob) { } + ~CodeBlobStub() { os::free((void*) name); } + const char* const name; + const jint size; + const jint blob_type; + const jlong address; + }; + + static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) { + jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string()); + CHECK_JNI_EXCEPTION_(env, NULL); + jobjectArray result = env->NewObjectArray(4, clazz, NULL); + + jstring name = env->NewStringUTF(cb->name); + CHECK_JNI_EXCEPTION_(env, NULL); + env->SetObjectArrayElement(result, 0, name); + + jobject obj = integerBox(thread, env, cb->size); + CHECK_JNI_EXCEPTION_(env, NULL); + env->SetObjectArrayElement(result, 1, obj); + + obj = integerBox(thread, env, cb->blob_type); + CHECK_JNI_EXCEPTION_(env, NULL); + env->SetObjectArrayElement(result, 2, obj); + + obj = longBox(thread, env, cb->address); + CHECK_JNI_EXCEPTION_(env, NULL); + env->SetObjectArrayElement(result, 3, obj); + + return result; + } WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) ResourceMark rm(THREAD); jmethodID jmid = reflected_method_to_jmid(thread, env, method); CHECK_JNI_EXCEPTION_(env, NULL);
*** 886,895 **** --- 967,1017 ---- env->SetObjectArrayElement(result, 2, insts); return result; WB_END + CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) { + guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); + BufferBlob* blob; + int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob)); + if (full_size < size) { + full_size += align_up(size - full_size, oopSize); + } + { + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); + blob = (BufferBlob*) CodeCache::allocate(full_size); + ::new (blob) BufferBlob("WB::DummyBlob", full_size); + } + // Track memory usage statistic after releasing CodeCache_lock + MemoryService::track_code_cache_memory_usage(); + return blob; + } + + WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type)) + if (size < 0) { + THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), + err_msg("WB_AllocateCodeBlob: size is negative: " INT32_FORMAT, size)); + } + return (jlong) WhiteBox::allocate_code_blob(size, blob_type); + WB_END + + WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr)) + if (addr == 0) { + return; + } + BufferBlob::free((BufferBlob*) addr); + WB_END + + WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr)) + if (addr == 0) { + THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), + "WB_GetCodeBlob: addr is null"); + } + ThreadToNativeFromVM ttn(thread); + CodeBlobStub stub((CodeBlob*) addr); + return codeBlob2objectArray(thread, env, &stub); + WB_END int WhiteBox::array_bytes_to_length(size_t bytes) { return Array<u1>::bytes_to_length(bytes); }
*** 957,966 **** --- 1079,1093 ---- WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb)) VM_ForceSafepoint force_safepoint_op; VMThread::execute(&force_safepoint_op); WB_END + WB_ENTRY(jlong, WB_GetHeapAlignment(JNIEnv* env, jobject o)) + size_t alignment = Universe::heap()->collector_policy()->heap_alignment(); + return (jlong)alignment; + WB_END + //Some convenience methods to deal with objects from java int WhiteBox::offset_for_field(const char* field_name, oop object, Symbol* signature_symbol) { assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid"); Thread* THREAD = Thread::current();
*** 1071,1080 **** --- 1198,1208 ---- {CC"getObjectSize", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize }, {CC"isObjectInOldGen", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen }, {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, {CC"getVMPageSize", CC"()I", (void*)&WB_GetVMPageSize }, {CC"getVMLargePageSize", CC"()J", (void*)&WB_GetVMLargePageSize}, + {CC"getHeapAlignment", CC"()J", (void*)&WB_GetHeapAlignment }, {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, {CC"classKnownToNotExist", CC"(Ljava/lang/ClassLoader;Ljava/lang/String;)Z",(void*)&WB_ClassKnownToNotExist}, {CC"getLookupCacheURLs", CC"(Ljava/lang/ClassLoader;)[Ljava/net/URL;", (void*)&WB_GetLookupCacheURLs}, {CC"getLookupCacheMatches", CC"(Ljava/lang/ClassLoader;Ljava/lang/String;)[I",
*** 1136,1147 **** CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci}, {CC"getCompileQueueSize", CC"(I)I", (void*)&WB_GetCompileQueueSize}, {CC"testSetForceInlineMethod", CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, ! {CC"enqueueMethodForCompilation", CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, {CC"clearMethodState", CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, {CC"markMethodProfiled", CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_MarkMethodProfiled}, {CC"setBooleanVMFlag", CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag}, --- 1264,1277 ---- CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci}, {CC"getCompileQueueSize", CC"(I)I", (void*)&WB_GetCompileQueueSize}, {CC"testSetForceInlineMethod", CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, ! {CC"enqueueMethodForCompilation0", CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, + {CC"enqueueInitializerForCompilation0", + CC"(Ljava/lang/Class;I)Z", (void*)&WB_EnqueueInitializerForCompilation}, {CC"clearMethodState", CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, {CC"markMethodProfiled", CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_MarkMethodProfiled}, {CC"setBooleanVMFlag", CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag},
*** 1165,1174 **** --- 1295,1307 ---- (void*)&WB_GetStringVMFlag}, {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, {CC"fullGC", CC"()V", (void*)&WB_FullGC }, {CC"youngGC", CC"()V", (void*)&WB_YoungGC }, {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, + {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob }, + {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob }, + {CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob }, {CC"allocateMetaspace", CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace }, {CC"freeMetaspace", CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace }, {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC },
< prev index next >