39 #include "runtime/compilationPolicy.hpp" |
39 #include "runtime/compilationPolicy.hpp" |
40 #include "runtime/deoptimization.hpp" |
40 #include "runtime/deoptimization.hpp" |
41 #include "runtime/interfaceSupport.hpp" |
41 #include "runtime/interfaceSupport.hpp" |
42 #include "runtime/os.hpp" |
42 #include "runtime/os.hpp" |
43 #include "runtime/sweeper.hpp" |
43 #include "runtime/sweeper.hpp" |
|
44 #include "runtime/javaCalls.hpp" |
44 #include "runtime/thread.hpp" |
45 #include "runtime/thread.hpp" |
45 #include "runtime/vm_version.hpp" |
46 #include "runtime/vm_version.hpp" |
46 #include "utilities/array.hpp" |
47 #include "utilities/array.hpp" |
47 #include "utilities/debug.hpp" |
48 #include "utilities/debug.hpp" |
48 #include "utilities/exceptions.hpp" |
49 #include "utilities/exceptions.hpp" |
757 MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag); |
758 MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag); |
758 WhiteBox::compilation_locked = false; |
759 WhiteBox::compilation_locked = false; |
759 mo.notify_all(); |
760 mo.notify_all(); |
760 WB_END |
761 WB_END |
761 |
762 |
762 void WhiteBox::force_sweep() { |
763 void WhiteBox::sweeper_thread_entry(JavaThread* thread, TRAPS) { |
763 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to enabled"); |
764 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); |
764 { |
765 { |
765 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
766 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
766 NMethodSweeper::_should_sweep = true; |
767 NMethodSweeper::_should_sweep = true; |
767 } |
768 } |
768 NMethodSweeper::possibly_sweep(); |
769 NMethodSweeper::possibly_sweep(); |
769 } |
770 } |
770 |
771 |
771 WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o)) |
772 JavaThread* WhiteBox::create_sweeper_thread(TRAPS) { |
772 WhiteBox::force_sweep(); |
773 // create sweeper thread w/ custom entry -- one iteration instead of loop |
|
774 CodeCacheSweeperThread* sweeper_thread = new CodeCacheSweeperThread(); |
|
775 sweeper_thread->set_entry_point(&WhiteBox::sweeper_thread_entry); |
|
776 |
|
777 // create j.l.Thread object and associate it w/ sweeper thread |
|
778 { |
|
779 // inherit deamon property from current thread |
|
780 bool is_daemon = java_lang_Thread::is_daemon(JavaThread::current()->threadObj()); |
|
781 |
|
782 HandleMark hm(THREAD); |
|
783 Handle thread_group(THREAD, Universe::system_thread_group()); |
|
784 const char* name = "WB Sweeper thread"; |
|
785 sweeper_thread->allocate_threadObj(thread_group, name, is_daemon, THREAD); |
|
786 } |
|
787 |
|
788 { |
|
789 MutexLocker mu(Threads_lock, THREAD); |
|
790 Threads::add(sweeper_thread); |
|
791 } |
|
792 return sweeper_thread; |
|
793 } |
|
794 |
|
795 WB_ENTRY(jobject, WB_ForceNMethodSweep(JNIEnv* env, jobject o)) |
|
796 JavaThread* sweeper_thread = WhiteBox::create_sweeper_thread(Thread::current()); |
|
797 if (sweeper_thread == NULL) { |
|
798 return NULL; |
|
799 } |
|
800 jobject result = JNIHandles::make_local(env, sweeper_thread->threadObj()); |
|
801 Thread::start(sweeper_thread); |
|
802 return result; |
773 WB_END |
803 WB_END |
774 |
804 |
775 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) |
805 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) |
776 ResourceMark rm(THREAD); |
806 ResourceMark rm(THREAD); |
777 int len; |
807 int len; |
817 |
847 |
818 return features_string; |
848 return features_string; |
819 WB_END |
849 WB_END |
820 |
850 |
821 int WhiteBox::get_blob_type(const CodeBlob* code) { |
851 int WhiteBox::get_blob_type(const CodeBlob* code) { |
822 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to enabled"); |
852 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); |
823 return CodeCache::get_code_heap(code)->code_blob_type(); |
853 return CodeCache::get_code_heap(code)->code_blob_type(); |
824 } |
854 } |
825 |
855 |
826 CodeHeap* WhiteBox::get_code_heap(int blob_type) { |
856 CodeHeap* WhiteBox::get_code_heap(int blob_type) { |
827 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to enabled"); |
857 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); |
828 return CodeCache::get_code_heap(blob_type); |
858 return CodeCache::get_code_heap(blob_type); |
829 } |
859 } |
830 |
860 |
831 struct CodeBlobStub { |
861 struct CodeBlobStub { |
832 CodeBlobStub(const CodeBlob* blob) : |
862 CodeBlobStub(const CodeBlob* blob) : |
898 |
928 |
899 return result; |
929 return result; |
900 WB_END |
930 WB_END |
901 |
931 |
902 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) { |
932 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) { |
903 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to enabled"); |
933 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); |
904 BufferBlob* blob; |
934 BufferBlob* blob; |
905 int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob)); |
935 int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob)); |
906 if (full_size < size) { |
936 if (full_size < size) { |
907 full_size += round_to(size - full_size, oopSize); |
937 full_size += round_to(size - full_size, oopSize); |
908 } |
938 } |
909 { |
939 { |
910 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
940 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
911 blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type); |
941 blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type); |
|
942 ::new (blob) BufferBlob("WB::DummyBlob", full_size); |
912 } |
943 } |
913 // Track memory usage statistic after releasing CodeCache_lock |
944 // Track memory usage statistic after releasing CodeCache_lock |
914 MemoryService::track_code_cache_memory_usage(); |
945 MemoryService::track_code_cache_memory_usage(); |
915 ::new (blob) BufferBlob("WB::DummyBlob", full_size); |
|
916 return blob; |
946 return blob; |
917 } |
947 } |
918 |
948 |
919 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type)) |
949 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type)) |
920 return (jlong) WhiteBox::allocate_code_blob(size, blob_type); |
950 return (jlong) WhiteBox::allocate_code_blob(size, blob_type); |
1219 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC }, |
1249 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC }, |
1220 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC }, |
1250 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC }, |
1221 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures }, |
1251 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures }, |
1222 {CC"getNMethod", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;", |
1252 {CC"getNMethod", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;", |
1223 (void*)&WB_GetNMethod }, |
1253 (void*)&WB_GetNMethod }, |
1224 {CC"forceNMethodSweep", CC"()V", (void*)&WB_ForceNMethodSweep }, |
1254 {CC"forceNMethodSweep0", CC"()Ljava/lang/Thread;", (void*)&WB_ForceNMethodSweep }, |
1225 {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob }, |
1255 {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob }, |
1226 {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob }, |
1256 {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob }, |
1227 {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries }, |
1257 {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries }, |
1228 {CC"getCompilationActivityMode", |
1258 {CC"getCompilationActivityMode", |
1229 CC"()I", (void*)&WB_GetCompilationActivityMode}, |
1259 CC"()I", (void*)&WB_GetCompilationActivityMode}, |