< prev index next >

src/share/vm/prims/jvmtiExport.cpp

Print this page




2365         }
2366       }
2367     }
2368     if (library != NULL) {
2369       agent_lib->set_os_lib(library);
2370       agent_lib->set_valid();
2371     }
2372   }
2373   // If the library was loaded then we attempt to invoke the Agent_OnAttach
2374   // function
2375   if (agent_lib->valid()) {
2376     // Lookup the Agent_OnAttach function
2377     OnAttachEntry_t on_attach_entry = NULL;
2378     on_attach_entry = CAST_TO_FN_PTR(OnAttachEntry_t,
2379        os::find_agent_function(agent_lib, false, on_attach_symbols, num_symbol_entries));
2380     if (on_attach_entry == NULL) {
2381       // Agent_OnAttach missing - unload library
2382       if (!agent_lib->is_static_lib()) {
2383         os::dll_unload(library);
2384       }

2385       delete agent_lib;
2386     } else {
2387       // Invoke the Agent_OnAttach function
2388       JavaThread* THREAD = JavaThread::current();
2389       {
2390         extern struct JavaVM_ main_vm;
2391         JvmtiThreadEventMark jem(THREAD);
2392         JvmtiJavaThreadEventTransition jet(THREAD);
2393 
2394         result = (*on_attach_entry)(&main_vm, (char*)options, NULL);
2395       }
2396 
2397       // Agent_OnAttach may have used JNI
2398       if (HAS_PENDING_EXCEPTION) {
2399         CLEAR_PENDING_EXCEPTION;
2400       }
2401 
2402       // If OnAttach returns JNI_OK then we add it to the list of
2403       // agent libraries so that we can call Agent_OnUnload later.
2404       if (result == JNI_OK) {
2405         Arguments::add_loaded_agent(agent_lib);
2406       } else {
2407         delete agent_lib;
2408       }
2409 
2410       // Agent_OnAttach executed so completion status is JNI_OK
2411       st->print_cr("%d", result);
2412       result = JNI_OK;
2413     }
2414   }





2415   return result;
2416 }
2417 
2418 #endif // INCLUDE_SERVICES
2419 ////////////////////////////////////////////////////////////////////////////////////////////////
2420 
2421 // Setup current current thread for event collection.
2422 void JvmtiEventCollector::setup_jvmti_thread_state() {
2423   // set this event collector to be the current one.
2424   JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
2425   // state can only be NULL if the current thread is exiting which
2426   // should not happen since we're trying to configure for event collection
2427   guarantee(state != NULL, "exiting thread called setup_jvmti_thread_state");
2428   if (is_vm_object_alloc_event()) {
2429     _prev = state->get_vm_object_alloc_event_collector();
2430     state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)this);
2431   } else if (is_dynamic_code_event()) {
2432     _prev = state->get_dynamic_code_event_collector();
2433     state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)this);
2434   }




2365         }
2366       }
2367     }
2368     if (library != NULL) {
2369       agent_lib->set_os_lib(library);
2370       agent_lib->set_valid();
2371     }
2372   }
2373   // If the library was loaded then we attempt to invoke the Agent_OnAttach
2374   // function
2375   if (agent_lib->valid()) {
2376     // Lookup the Agent_OnAttach function
2377     OnAttachEntry_t on_attach_entry = NULL;
2378     on_attach_entry = CAST_TO_FN_PTR(OnAttachEntry_t,
2379        os::find_agent_function(agent_lib, false, on_attach_symbols, num_symbol_entries));
2380     if (on_attach_entry == NULL) {
2381       // Agent_OnAttach missing - unload library
2382       if (!agent_lib->is_static_lib()) {
2383         os::dll_unload(library);
2384       }
2385       st->print_cr("Could not find entry point in %s\n", agent_lib->name());
2386       delete agent_lib;
2387     } else {
2388       // Invoke the Agent_OnAttach function
2389       JavaThread* THREAD = JavaThread::current();
2390       {
2391         extern struct JavaVM_ main_vm;
2392         JvmtiThreadEventMark jem(THREAD);
2393         JvmtiJavaThreadEventTransition jet(THREAD);
2394 
2395         result = (*on_attach_entry)(&main_vm, (char*)options, NULL);
2396       }
2397 
2398       // Agent_OnAttach may have used JNI
2399       if (HAS_PENDING_EXCEPTION) {
2400         CLEAR_PENDING_EXCEPTION;
2401       }
2402 
2403       // If OnAttach returns JNI_OK then we add it to the list of
2404       // agent libraries so that we can call Agent_OnUnload later.
2405       if (result == JNI_OK) {
2406         Arguments::add_loaded_agent(agent_lib);
2407       } else {
2408         delete agent_lib;
2409       }
2410 
2411       // Agent_OnAttach executed so completion status is JNI_OK
2412       st->print_cr("%d", result);
2413       result = JNI_OK;
2414     }
2415   }
2416 
2417   if ((result != JNI_OK) && (*ebuf != '0')) {
2418     st->print_cr("%s\n", ebuf);
2419   }
2420 
2421   return result;
2422 }
2423 
2424 #endif // INCLUDE_SERVICES
2425 ////////////////////////////////////////////////////////////////////////////////////////////////
2426 
2427 // Setup current current thread for event collection.
2428 void JvmtiEventCollector::setup_jvmti_thread_state() {
2429   // set this event collector to be the current one.
2430   JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
2431   // state can only be NULL if the current thread is exiting which
2432   // should not happen since we're trying to configure for event collection
2433   guarantee(state != NULL, "exiting thread called setup_jvmti_thread_state");
2434   if (is_vm_object_alloc_event()) {
2435     _prev = state->get_vm_object_alloc_event_collector();
2436     state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)this);
2437   } else if (is_dynamic_code_event()) {
2438     _prev = state->get_dynamic_code_event_collector();
2439     state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)this);
2440   }


< prev index next >