726 if (value != NULL) {
727 env->ReleaseStringUTFChars(value, ccstrValue);
728 }
729 if (needFree) {
730 FREE_C_HEAP_ARRAY(char, ccstrResult, mtInternal);
731 }
732 WB_END
733
734
735 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
736 WhiteBox::compilation_locked = true;
737 WB_END
738
739 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
740 MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
741 WhiteBox::compilation_locked = false;
742 mo.notify_all();
743 WB_END
744
745 void WhiteBox::force_sweep() {
746 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to enabled");
747 {
748 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
749 NMethodSweeper::_should_sweep = true;
750 }
751 NMethodSweeper::possibly_sweep();
752 }
753
754 WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
755 WhiteBox::force_sweep();
756 WB_END
757
758 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
759 ResourceMark rm(THREAD);
760 int len;
761 jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
762 return (StringTable::lookup(name, len) != NULL);
763 WB_END
764
765 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
766 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
785
786 p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
787 if (p == NULL) {
788 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
789 }
790
791 c = *p;
792 WB_END
793
794 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o))
795 const char* cpu_features = VM_Version::cpu_features();
796 ThreadToNativeFromVM ttn(thread);
797 jstring features_string = env->NewStringUTF(cpu_features);
798
799 CHECK_JNI_EXCEPTION_(env, NULL);
800
801 return features_string;
802 WB_END
803
804 int WhiteBox::get_blob_type(const CodeBlob* code) {
805 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to enabled");
806 return CodeCache::get_code_heap(code)->code_blob_type();
807 }
808
809 CodeHeap* WhiteBox::get_code_heap(int blob_type) {
810 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to enabled");
811 return CodeCache::get_code_heap(blob_type);
812 }
813
814 struct CodeBlobStub {
815 CodeBlobStub(const CodeBlob* blob) :
816 name(os::strdup(blob->name())),
817 size(blob->size()),
818 blob_type(WhiteBox::get_blob_type(blob)) { }
819 ~CodeBlobStub() { os::free((void*) name); }
820 const char* const name;
821 const int size;
822 const int blob_type;
823 };
824
825 static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) {
826 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
827 CHECK_JNI_EXCEPTION_(env, NULL);
828 jobjectArray result = env->NewObjectArray(3, clazz, NULL);
829
830 jstring name = env->NewStringUTF(cb->name);
866 jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
867 env->SetObjectArrayElement(result, 0, codeBlob);
868
869 jobject level = integerBox(thread, env, code->comp_level());
870 CHECK_JNI_EXCEPTION_(env, NULL);
871 env->SetObjectArrayElement(result, 1, level);
872
873 jbyteArray insts = env->NewByteArray(insts_size);
874 CHECK_JNI_EXCEPTION_(env, NULL);
875 env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
876 env->SetObjectArrayElement(result, 2, insts);
877
878 jobject id = integerBox(thread, env, code->compile_id());
879 CHECK_JNI_EXCEPTION_(env, NULL);
880 env->SetObjectArrayElement(result, 3, id);
881
882 return result;
883 WB_END
884
885 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
886 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to enabled");
887 BufferBlob* blob;
888 int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
889 if (full_size < size) {
890 full_size += round_to(size - full_size, oopSize);
891 }
892 {
893 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
894 blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
895 }
896 // Track memory usage statistic after releasing CodeCache_lock
897 MemoryService::track_code_cache_memory_usage();
898 ::new (blob) BufferBlob("WB::DummyBlob", full_size);
899 return blob;
900 }
901
902 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type))
903 return (jlong) WhiteBox::allocate_code_blob(size, blob_type);
904 WB_END
905
906 WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr))
907 BufferBlob::free((BufferBlob*) addr);
908 WB_END
909
910 WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type))
911 ResourceMark rm;
912 GrowableArray<CodeBlobStub*> blobs;
913 {
914 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
915 CodeHeap* heap = WhiteBox::get_code_heap(blob_type);
916 if (heap == NULL) {
917 return NULL;
918 }
|
726 if (value != NULL) {
727 env->ReleaseStringUTFChars(value, ccstrValue);
728 }
729 if (needFree) {
730 FREE_C_HEAP_ARRAY(char, ccstrResult, mtInternal);
731 }
732 WB_END
733
734
735 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
736 WhiteBox::compilation_locked = true;
737 WB_END
738
739 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
740 MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
741 WhiteBox::compilation_locked = false;
742 mo.notify_all();
743 WB_END
744
745 void WhiteBox::force_sweep() {
746 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
747 {
748 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
749 NMethodSweeper::_should_sweep = true;
750 }
751 NMethodSweeper::possibly_sweep();
752 }
753
754 WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
755 WhiteBox::force_sweep();
756 WB_END
757
758 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
759 ResourceMark rm(THREAD);
760 int len;
761 jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
762 return (StringTable::lookup(name, len) != NULL);
763 WB_END
764
765 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
766 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
785
786 p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
787 if (p == NULL) {
788 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
789 }
790
791 c = *p;
792 WB_END
793
794 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o))
795 const char* cpu_features = VM_Version::cpu_features();
796 ThreadToNativeFromVM ttn(thread);
797 jstring features_string = env->NewStringUTF(cpu_features);
798
799 CHECK_JNI_EXCEPTION_(env, NULL);
800
801 return features_string;
802 WB_END
803
804 int WhiteBox::get_blob_type(const CodeBlob* code) {
805 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
806 return CodeCache::get_code_heap(code)->code_blob_type();
807 }
808
809 CodeHeap* WhiteBox::get_code_heap(int blob_type) {
810 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
811 return CodeCache::get_code_heap(blob_type);
812 }
813
814 struct CodeBlobStub {
815 CodeBlobStub(const CodeBlob* blob) :
816 name(os::strdup(blob->name())),
817 size(blob->size()),
818 blob_type(WhiteBox::get_blob_type(blob)) { }
819 ~CodeBlobStub() { os::free((void*) name); }
820 const char* const name;
821 const int size;
822 const int blob_type;
823 };
824
825 static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) {
826 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
827 CHECK_JNI_EXCEPTION_(env, NULL);
828 jobjectArray result = env->NewObjectArray(3, clazz, NULL);
829
830 jstring name = env->NewStringUTF(cb->name);
866 jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
867 env->SetObjectArrayElement(result, 0, codeBlob);
868
869 jobject level = integerBox(thread, env, code->comp_level());
870 CHECK_JNI_EXCEPTION_(env, NULL);
871 env->SetObjectArrayElement(result, 1, level);
872
873 jbyteArray insts = env->NewByteArray(insts_size);
874 CHECK_JNI_EXCEPTION_(env, NULL);
875 env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
876 env->SetObjectArrayElement(result, 2, insts);
877
878 jobject id = integerBox(thread, env, code->compile_id());
879 CHECK_JNI_EXCEPTION_(env, NULL);
880 env->SetObjectArrayElement(result, 3, id);
881
882 return result;
883 WB_END
884
885 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
886 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
887 BufferBlob* blob;
888 int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
889 if (full_size < size) {
890 full_size += round_to(size - full_size, oopSize);
891 }
892 {
893 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
894 blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
895 ::new (blob) BufferBlob("WB::DummyBlob", full_size);
896 }
897 // Track memory usage statistic after releasing CodeCache_lock
898 MemoryService::track_code_cache_memory_usage();
899 return blob;
900 }
901
902 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type))
903 return (jlong) WhiteBox::allocate_code_blob(size, blob_type);
904 WB_END
905
906 WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr))
907 BufferBlob::free((BufferBlob*) addr);
908 WB_END
909
910 WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type))
911 ResourceMark rm;
912 GrowableArray<CodeBlobStub*> blobs;
913 {
914 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
915 CodeHeap* heap = WhiteBox::get_code_heap(blob_type);
916 if (heap == NULL) {
917 return NULL;
918 }
|