< prev index next >

src/share/vm/prims/whitebox.cpp

Print this page




 798 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
 799   WhiteBox::compilation_locked = true;
 800 WB_END
 801 
 802 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
 803   MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
 804   WhiteBox::compilation_locked = false;
 805   mo.notify_all();
 806 WB_END
 807 
 808 void WhiteBox::sweeper_thread_entry(JavaThread* thread, TRAPS) {
 809   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
 810   {
 811     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 812     NMethodSweeper::_should_sweep = true;
 813   }
 814   NMethodSweeper::possibly_sweep();
 815 }
 816 
 817 JavaThread* WhiteBox::create_sweeper_thread(TRAPS) {






























 818   // create sweeper thread w/ custom entry -- one iteration instead of loop
 819   CodeCacheSweeperThread* sweeper_thread = new CodeCacheSweeperThread();
 820   sweeper_thread->set_entry_point(&WhiteBox::sweeper_thread_entry);
 821 
 822   // create j.l.Thread object and associate it w/ sweeper thread
 823   {
 824     // inherit deamon property from current thread
 825     bool is_daemon = java_lang_Thread::is_daemon(JavaThread::current()->threadObj());

 826 
 827     HandleMark hm(THREAD);
 828     Handle thread_group(THREAD, Universe::system_thread_group());
 829     const char* name = "WB Sweeper thread";
 830     sweeper_thread->allocate_threadObj(thread_group, name, is_daemon, THREAD);
 831   }
 832 
 833   {
 834     MutexLocker mu(Threads_lock, THREAD);


 835     Threads::add(sweeper_thread);
 836   }
 837   return sweeper_thread;

 838 }
 839 
 840 WB_ENTRY(jobject, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
 841   JavaThread* sweeper_thread = WhiteBox::create_sweeper_thread(Thread::current());
 842   if (sweeper_thread == NULL) {
 843     return NULL;
 844   }
 845   jobject result = JNIHandles::make_local(env, sweeper_thread->threadObj());
 846   Thread::start(sweeper_thread);
 847   return result;
 848 WB_END
 849 
 850 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
 851   ResourceMark rm(THREAD);
 852   int len;
 853   jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
 854   return (StringTable::lookup(name, len) != NULL);
 855 WB_END
 856 
 857 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))




 798 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
 799   WhiteBox::compilation_locked = true;
 800 WB_END
 801 
 802 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
 803   MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
 804   WhiteBox::compilation_locked = false;
 805   mo.notify_all();
 806 WB_END
 807 
 808 void WhiteBox::sweeper_thread_entry(JavaThread* thread, TRAPS) {
 809   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
 810   {
 811     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 812     NMethodSweeper::_should_sweep = true;
 813   }
 814   NMethodSweeper::possibly_sweep();
 815 }
 816 
 817 JavaThread* WhiteBox::create_sweeper_thread(TRAPS) {
 818   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, THREAD);
 819   instanceKlassHandle klass(THREAD, k);
 820   instanceHandle thread_oop = klass->allocate_instance_handle(THREAD);
 821 
 822   Handle name = java_lang_String::create_from_str("WB Sweeper thread", THREAD);
 823 
 824   // Initialize thread_oop to put it into the system threadGroup
 825   Handle thread_group(THREAD, Universe::system_thread_group());
 826   JavaValue result(T_VOID);
 827   JavaCalls::call_special(&result,
 828                           thread_oop,
 829                           klass,
 830                           vmSymbols::object_initializer_name(),
 831                           vmSymbols::threadgroup_string_void_signature(),
 832                           thread_group,
 833                           name,
 834                           THREAD);
 835 
 836   KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
 837   JavaCalls::call_special(&result,
 838                           thread_group,
 839                           group,
 840                           vmSymbols::add_method_name(),
 841                           vmSymbols::thread_void_signature(),
 842                           thread_oop,             // ARG 1
 843                           THREAD);
 844 
 845   {
 846     MutexLocker mu(Threads_lock);
 847 
 848     // create sweeper thread w/ custom entry -- one iteration instead of loop
 849     CodeCacheSweeperThread* sweeper_thread = new CodeCacheSweeperThread();
 850     sweeper_thread->set_entry_point(&WhiteBox::sweeper_thread_entry);
 851 
 852     // check that thread and osthread were created
 853     if (sweeper_thread == NULL || sweeper_thread->osthread() == NULL) {
 854       vm_exit_during_initialization("java.lang.OutOfMemoryError",
 855                                     os::native_thread_creation_failed_msg());
 856     }
 857 
 858     java_lang_Thread::set_thread(thread_oop(), sweeper_thread);
 859     // inherit daemon property from current thread
 860     if (java_lang_Thread::is_daemon(JavaThread::current()->threadObj())) {
 861       java_lang_Thread::set_daemon(thread_oop());
 862     }
 863 
 864     // Make sure that both the thread_oop is set and the thread is added to
 865     // the threads list before a safepoint can happen. Otherwise, a GC may
 866     // move the thread object without updating the oop.
 867     sweeper_thread->set_threadObj(thread_oop());
 868     Threads::add(sweeper_thread);

 869     return sweeper_thread;
 870   }
 871 }
 872 
 873 WB_ENTRY(jobject, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
 874   JavaThread* sweeper_thread = WhiteBox::create_sweeper_thread(Thread::current());
 875   if (sweeper_thread == NULL) {
 876     return NULL;
 877   }
 878   jobject result = JNIHandles::make_local(env, sweeper_thread->threadObj());
 879   Thread::start(sweeper_thread);
 880   return result;
 881 WB_END
 882 
 883 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
 884   ResourceMark rm(THREAD);
 885   int len;
 886   jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
 887   return (StringTable::lookup(name, len) != NULL);
 888 WB_END
 889 
 890 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))


< prev index next >