--- old/src/share/vm/prims/whitebox.cpp 2019-01-28 17:44:16.000000000 +0800 +++ new/src/share/vm/prims/whitebox.cpp 2019-01-28 17:44:16.000000000 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2019, 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 @@ -60,6 +60,7 @@ #include "compiler/compileBroker.hpp" #include "jvmtifiles/jvmtiEnv.hpp" #include "runtime/compilationPolicy.hpp" +#include "jfr/utilities/align.hpp" PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC @@ -569,6 +570,14 @@ return (mh->queued_for_compilation() || nm != NULL); 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))); + methodHandle mh(THREAD, ik->class_initializer()); + nmethod* nm = CompileBroker::compile_method(mh, InvocationEntryBci, 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() { } @@ -643,6 +652,18 @@ } template +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 static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAtPut)(const char*, T*, Flag::Flags)) { if (name == NULL) { return false; @@ -862,6 +883,37 @@ 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 int WhiteBox::array_bytes_to_length(size_t bytes) { return Array::bytes_to_length(bytes); @@ -933,6 +985,11 @@ 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) { @@ -1111,6 +1168,8 @@ CC"(I)I", (void*)&WB_GetCompileQueueSize}, {CC"testSetForceInlineMethod", CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, + {CC"enqueueInitializerForCompilation", + CC"(Ljava/lang/Class;I)Z", (void*)&WB_EnqueueInitializerForCompilation}, {CC"enqueueMethodForCompilation", CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, {CC"clearMethodState", @@ -1153,6 +1212,8 @@ (void*)&WB_CheckLibSpecifiesNoexecstack}, {CC"isContainerized", CC"()Z", (void*)&WB_IsContainerized }, {CC"printOsInfo", CC"()V", (void*)&WB_PrintOsInfo }, + {CC"getHeapAlignment", CC"()J", (void*)&WB_GetHeapAlignment}, + {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob }, }; #undef CC