357
358 // micro version doesn't matter here (yet?)
359 decode_version_values(version, &major, &minor, µ);
360 switch (major) {
361 case 1:
362 switch (minor) {
363 case 0: // version 1.0.<micro> is recognized
364 case 1: // version 1.1.<micro> is recognized
365 case 2: // version 1.2.<micro> is recognized
366 break;
367
368 default:
369 return JNI_EVERSION; // unsupported minor version number
370 }
371 break;
372 default:
373 return JNI_EVERSION; // unsupported major version number
374 }
375
376 if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) {
377 JavaThread* current_thread = (JavaThread*) ThreadLocalStorage::thread();
378 // transition code: native to VM
379 ThreadInVMfromNative __tiv(current_thread);
380 VM_ENTRY_BASE(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread)
381 debug_only(VMNativeEntryWrapper __vew;)
382
383 JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
384 *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
385 return JNI_OK;
386
387 } else if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) {
388 // not live, no thread to transition
389 JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
390 *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
391 return JNI_OK;
392
393 } else {
394 // Called at the wrong time
395 *penv = NULL;
396 return JNI_EDETACHED;
397 }
1884 }
1885 }
1886 }
1887
1888 // post a DynamicCodeGenerated event while holding locks in the VM.
1889 void JvmtiExport::post_dynamic_code_generated_while_holding_locks(const char* name,
1890 address code_begin, address code_end)
1891 {
1892 // register the stub with the current dynamic code event collector
1893 JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
1894 // state can only be NULL if the current thread is exiting which
1895 // should not happen since we're trying to post an event
1896 guarantee(state != NULL, "attempt to register stub via an exiting thread");
1897 JvmtiDynamicCodeEventCollector* collector = state->get_dynamic_code_event_collector();
1898 guarantee(collector != NULL, "attempt to register stub without event collector");
1899 collector->register_stub(name, code_begin, code_end);
1900 }
1901
1902 // Collect all the vm internally allocated objects which are visible to java world
1903 void JvmtiExport::record_vm_internal_object_allocation(oop obj) {
1904 Thread* thread = ThreadLocalStorage::thread();
1905 if (thread != NULL && thread->is_Java_thread()) {
1906 // Can not take safepoint here.
1907 No_Safepoint_Verifier no_sfpt;
1908 // Can not take safepoint here so can not use state_for to get
1909 // jvmti thread state.
1910 JvmtiThreadState *state = ((JavaThread*)thread)->jvmti_thread_state();
1911 if (state != NULL ) {
1912 // state is non NULL when VMObjectAllocEventCollector is enabled.
1913 JvmtiVMObjectAllocEventCollector *collector;
1914 collector = state->get_vm_object_alloc_event_collector();
1915 if (collector != NULL && collector->is_enabled()) {
1916 // Don't record classes as these will be notified via the ClassLoad
1917 // event.
1918 if (obj->klass() != SystemDictionary::Class_klass()) {
1919 collector->record_allocation(obj);
1920 }
1921 }
1922 }
1923 }
1924 }
2419 for (JavaThread *jthr = Threads::first(); jthr != NULL; jthr = jthr->next()) {
2420 JvmtiThreadState *state = jthr->jvmti_thread_state();
2421 if (state != NULL) {
2422 JvmtiVMObjectAllocEventCollector *collector;
2423 collector = state->get_vm_object_alloc_event_collector();
2424 while (collector != NULL) {
2425 collector->oops_do(f);
2426 collector = (JvmtiVMObjectAllocEventCollector *)collector->get_prev();
2427 }
2428 }
2429 }
2430 }
2431
2432
2433 // Disable collection of VMObjectAlloc events
2434 NoJvmtiVMObjectAllocMark::NoJvmtiVMObjectAllocMark() : _collector(NULL) {
2435 // a no-op if VMObjectAlloc event is not enabled
2436 if (!JvmtiExport::should_post_vm_object_alloc()) {
2437 return;
2438 }
2439 Thread* thread = ThreadLocalStorage::thread();
2440 if (thread != NULL && thread->is_Java_thread()) {
2441 JavaThread* current_thread = (JavaThread*)thread;
2442 JvmtiThreadState *state = current_thread->jvmti_thread_state();
2443 if (state != NULL) {
2444 JvmtiVMObjectAllocEventCollector *collector;
2445 collector = state->get_vm_object_alloc_event_collector();
2446 if (collector != NULL && collector->is_enabled()) {
2447 _collector = collector;
2448 _collector->set_enabled(false);
2449 }
2450 }
2451 }
2452 }
2453
2454 // Re-Enable collection of VMObjectAlloc events (if previously enabled)
2455 NoJvmtiVMObjectAllocMark::~NoJvmtiVMObjectAllocMark() {
2456 if (was_enabled()) {
2457 _collector->set_enabled(true);
2458 }
2459 };
|
357
358 // micro version doesn't matter here (yet?)
359 decode_version_values(version, &major, &minor, µ);
360 switch (major) {
361 case 1:
362 switch (minor) {
363 case 0: // version 1.0.<micro> is recognized
364 case 1: // version 1.1.<micro> is recognized
365 case 2: // version 1.2.<micro> is recognized
366 break;
367
368 default:
369 return JNI_EVERSION; // unsupported minor version number
370 }
371 break;
372 default:
373 return JNI_EVERSION; // unsupported major version number
374 }
375
376 if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) {
377 JavaThread* current_thread = JavaThread::current();
378 // transition code: native to VM
379 ThreadInVMfromNative __tiv(current_thread);
380 VM_ENTRY_BASE(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread)
381 debug_only(VMNativeEntryWrapper __vew;)
382
383 JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
384 *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
385 return JNI_OK;
386
387 } else if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) {
388 // not live, no thread to transition
389 JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
390 *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
391 return JNI_OK;
392
393 } else {
394 // Called at the wrong time
395 *penv = NULL;
396 return JNI_EDETACHED;
397 }
1884 }
1885 }
1886 }
1887
1888 // post a DynamicCodeGenerated event while holding locks in the VM.
1889 void JvmtiExport::post_dynamic_code_generated_while_holding_locks(const char* name,
1890 address code_begin, address code_end)
1891 {
1892 // register the stub with the current dynamic code event collector
1893 JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
1894 // state can only be NULL if the current thread is exiting which
1895 // should not happen since we're trying to post an event
1896 guarantee(state != NULL, "attempt to register stub via an exiting thread");
1897 JvmtiDynamicCodeEventCollector* collector = state->get_dynamic_code_event_collector();
1898 guarantee(collector != NULL, "attempt to register stub without event collector");
1899 collector->register_stub(name, code_begin, code_end);
1900 }
1901
1902 // Collect all the vm internally allocated objects which are visible to java world
1903 void JvmtiExport::record_vm_internal_object_allocation(oop obj) {
1904 Thread* thread = Thread::current_or_null();
1905 if (thread != NULL && thread->is_Java_thread()) {
1906 // Can not take safepoint here.
1907 No_Safepoint_Verifier no_sfpt;
1908 // Can not take safepoint here so can not use state_for to get
1909 // jvmti thread state.
1910 JvmtiThreadState *state = ((JavaThread*)thread)->jvmti_thread_state();
1911 if (state != NULL ) {
1912 // state is non NULL when VMObjectAllocEventCollector is enabled.
1913 JvmtiVMObjectAllocEventCollector *collector;
1914 collector = state->get_vm_object_alloc_event_collector();
1915 if (collector != NULL && collector->is_enabled()) {
1916 // Don't record classes as these will be notified via the ClassLoad
1917 // event.
1918 if (obj->klass() != SystemDictionary::Class_klass()) {
1919 collector->record_allocation(obj);
1920 }
1921 }
1922 }
1923 }
1924 }
2419 for (JavaThread *jthr = Threads::first(); jthr != NULL; jthr = jthr->next()) {
2420 JvmtiThreadState *state = jthr->jvmti_thread_state();
2421 if (state != NULL) {
2422 JvmtiVMObjectAllocEventCollector *collector;
2423 collector = state->get_vm_object_alloc_event_collector();
2424 while (collector != NULL) {
2425 collector->oops_do(f);
2426 collector = (JvmtiVMObjectAllocEventCollector *)collector->get_prev();
2427 }
2428 }
2429 }
2430 }
2431
2432
2433 // Disable collection of VMObjectAlloc events
2434 NoJvmtiVMObjectAllocMark::NoJvmtiVMObjectAllocMark() : _collector(NULL) {
2435 // a no-op if VMObjectAlloc event is not enabled
2436 if (!JvmtiExport::should_post_vm_object_alloc()) {
2437 return;
2438 }
2439 Thread* thread = Thread::current_or_null();
2440 if (thread != NULL && thread->is_Java_thread()) {
2441 JavaThread* current_thread = (JavaThread*)thread;
2442 JvmtiThreadState *state = current_thread->jvmti_thread_state();
2443 if (state != NULL) {
2444 JvmtiVMObjectAllocEventCollector *collector;
2445 collector = state->get_vm_object_alloc_event_collector();
2446 if (collector != NULL && collector->is_enabled()) {
2447 _collector = collector;
2448 _collector->set_enabled(false);
2449 }
2450 }
2451 }
2452 }
2453
2454 // Re-Enable collection of VMObjectAlloc events (if previously enabled)
2455 NoJvmtiVMObjectAllocMark::~NoJvmtiVMObjectAllocMark() {
2456 if (was_enabled()) {
2457 _collector->set_enabled(true);
2458 }
2459 };
|