< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page




2458 void JvmtiExport::gc_epilogue() {
2459   JvmtiCurrentBreakpoints::gc_epilogue();
2460 }
2461 
2462 // Onload raw monitor transition.
2463 void JvmtiExport::transition_pending_onload_raw_monitors() {
2464   JvmtiPendingMonitors::transition_raw_monitors();
2465 }
2466 
2467 ////////////////////////////////////////////////////////////////////////////////////////////////
2468 #if INCLUDE_SERVICES
2469 // Attach is disabled if SERVICES is not included
2470 
2471 // type for the Agent_OnAttach entry point
2472 extern "C" {
2473   typedef jint (JNICALL *OnAttachEntry_t)(JavaVM*, char *, void *);
2474 }
2475 
2476 jint JvmtiExport::load_agent_library(const char *agent, const char *absParam,
2477                                      const char *options, outputStream* st) {
2478   char ebuf[1024];
2479   char buffer[JVM_MAXPATHLEN];
2480   void* library = NULL;
2481   jint result = JNI_ERR;
2482   const char *on_attach_symbols[] = AGENT_ONATTACH_SYMBOLS;
2483   size_t num_symbol_entries = ARRAY_SIZE(on_attach_symbols);
2484 
2485   // The abs paramter should be "true" or "false"
2486   bool is_absolute_path = (absParam != NULL) && (strcmp(absParam,"true")==0);
2487 
2488   // Initially marked as invalid. It will be set to valid if we can find the agent
2489   AgentLibrary *agent_lib = new AgentLibrary(agent, options, is_absolute_path, NULL);
2490 
2491   // Check for statically linked in agent. If not found then if the path is
2492   // absolute we attempt to load the library. Otherwise we try to load it
2493   // from the standard dll directory.
2494 
2495   if (!os::find_builtin_agent(agent_lib, on_attach_symbols, num_symbol_entries)) {
2496     if (is_absolute_path) {
2497       library = os::dll_load(agent, ebuf, sizeof ebuf);
2498     } else {


2508         }
2509       }
2510     }
2511     if (library != NULL) {
2512       agent_lib->set_os_lib(library);
2513       agent_lib->set_valid();
2514     }
2515   }
2516   // If the library was loaded then we attempt to invoke the Agent_OnAttach
2517   // function
2518   if (agent_lib->valid()) {
2519     // Lookup the Agent_OnAttach function
2520     OnAttachEntry_t on_attach_entry = NULL;
2521     on_attach_entry = CAST_TO_FN_PTR(OnAttachEntry_t,
2522        os::find_agent_function(agent_lib, false, on_attach_symbols, num_symbol_entries));
2523     if (on_attach_entry == NULL) {
2524       // Agent_OnAttach missing - unload library
2525       if (!agent_lib->is_static_lib()) {
2526         os::dll_unload(library);
2527       }


2528       delete agent_lib;
2529     } else {
2530       // Invoke the Agent_OnAttach function
2531       JavaThread* THREAD = JavaThread::current();
2532       {
2533         extern struct JavaVM_ main_vm;
2534         JvmtiThreadEventMark jem(THREAD);
2535         JvmtiJavaThreadEventTransition jet(THREAD);
2536 
2537         result = (*on_attach_entry)(&main_vm, (char*)options, NULL);
2538       }
2539 
2540       // Agent_OnAttach may have used JNI
2541       if (HAS_PENDING_EXCEPTION) {


2542         CLEAR_PENDING_EXCEPTION;
2543       }
2544 
2545       // If OnAttach returns JNI_OK then we add it to the list of
2546       // agent libraries so that we can call Agent_OnUnload later.
2547       if (result == JNI_OK) {
2548         Arguments::add_loaded_agent(agent_lib);
2549       } else {
2550         delete agent_lib;
2551       }
2552 
2553       // Agent_OnAttach executed so completion status is JNI_OK
2554       st->print_cr("%d", result);
2555       result = JNI_OK;
2556     }





2557   }

2558   return result;
2559 }
2560 
2561 #endif // INCLUDE_SERVICES
2562 ////////////////////////////////////////////////////////////////////////////////////////////////
2563 
2564 // Setup current current thread for event collection.
2565 void JvmtiEventCollector::setup_jvmti_thread_state() {
2566   // set this event collector to be the current one.
2567   JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
2568   // state can only be NULL if the current thread is exiting which
2569   // should not happen since we're trying to configure for event collection
2570   guarantee(state != NULL, "exiting thread called setup_jvmti_thread_state");
2571   if (is_vm_object_alloc_event()) {
2572     _prev = state->get_vm_object_alloc_event_collector();
2573     state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)this);
2574   } else if (is_dynamic_code_event()) {
2575     _prev = state->get_dynamic_code_event_collector();
2576     state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)this);
2577   }




2458 void JvmtiExport::gc_epilogue() {
2459   JvmtiCurrentBreakpoints::gc_epilogue();
2460 }
2461 
2462 // Onload raw monitor transition.
2463 void JvmtiExport::transition_pending_onload_raw_monitors() {
2464   JvmtiPendingMonitors::transition_raw_monitors();
2465 }
2466 
2467 ////////////////////////////////////////////////////////////////////////////////////////////////
2468 #if INCLUDE_SERVICES
2469 // Attach is disabled if SERVICES is not included
2470 
2471 // type for the Agent_OnAttach entry point
2472 extern "C" {
2473   typedef jint (JNICALL *OnAttachEntry_t)(JavaVM*, char *, void *);
2474 }
2475 
2476 jint JvmtiExport::load_agent_library(const char *agent, const char *absParam,
2477                                      const char *options, outputStream* st) {
2478   char ebuf[1024] = {0};
2479   char buffer[JVM_MAXPATHLEN];
2480   void* library = NULL;
2481   jint result = JNI_ERR;
2482   const char *on_attach_symbols[] = AGENT_ONATTACH_SYMBOLS;
2483   size_t num_symbol_entries = ARRAY_SIZE(on_attach_symbols);
2484 
2485   // The abs paramter should be "true" or "false"
2486   bool is_absolute_path = (absParam != NULL) && (strcmp(absParam,"true")==0);
2487 
2488   // Initially marked as invalid. It will be set to valid if we can find the agent
2489   AgentLibrary *agent_lib = new AgentLibrary(agent, options, is_absolute_path, NULL);
2490 
2491   // Check for statically linked in agent. If not found then if the path is
2492   // absolute we attempt to load the library. Otherwise we try to load it
2493   // from the standard dll directory.
2494 
2495   if (!os::find_builtin_agent(agent_lib, on_attach_symbols, num_symbol_entries)) {
2496     if (is_absolute_path) {
2497       library = os::dll_load(agent, ebuf, sizeof ebuf);
2498     } else {


2508         }
2509       }
2510     }
2511     if (library != NULL) {
2512       agent_lib->set_os_lib(library);
2513       agent_lib->set_valid();
2514     }
2515   }
2516   // If the library was loaded then we attempt to invoke the Agent_OnAttach
2517   // function
2518   if (agent_lib->valid()) {
2519     // Lookup the Agent_OnAttach function
2520     OnAttachEntry_t on_attach_entry = NULL;
2521     on_attach_entry = CAST_TO_FN_PTR(OnAttachEntry_t,
2522        os::find_agent_function(agent_lib, false, on_attach_symbols, num_symbol_entries));
2523     if (on_attach_entry == NULL) {
2524       // Agent_OnAttach missing - unload library
2525       if (!agent_lib->is_static_lib()) {
2526         os::dll_unload(library);
2527       }
2528       st->print_cr("%s is not available in %s",
2529                    on_attach_symbols[0], agent_lib->name());
2530       delete agent_lib;
2531     } else {
2532       // Invoke the Agent_OnAttach function
2533       JavaThread* THREAD = JavaThread::current();
2534       {
2535         extern struct JavaVM_ main_vm;
2536         JvmtiThreadEventMark jem(THREAD);
2537         JvmtiJavaThreadEventTransition jet(THREAD);
2538 
2539         result = (*on_attach_entry)(&main_vm, (char*)options, NULL);
2540       }
2541 
2542       // Agent_OnAttach may have used JNI
2543       if (HAS_PENDING_EXCEPTION) {
2544         java_lang_Throwable::print(PENDING_EXCEPTION, st);
2545         st->cr();
2546         CLEAR_PENDING_EXCEPTION;
2547       }
2548 
2549       // If OnAttach returns JNI_OK then we add it to the list of
2550       // agent libraries so that we can call Agent_OnUnload later.
2551       if (result == JNI_OK) {
2552         Arguments::add_loaded_agent(agent_lib);
2553       } else {
2554         delete agent_lib;
2555       }
2556 
2557       st->print_cr("return code: %d", result);

2558       result = JNI_OK;
2559     }
2560   } else {
2561     st->print_cr("%s was not loaded.", agent);
2562     if (*ebuf != '\0') {
2563       st->print_cr("%s", ebuf);
2564     }
2565   }
2566 
2567   return result;
2568 }
2569 
2570 #endif // INCLUDE_SERVICES
2571 ////////////////////////////////////////////////////////////////////////////////////////////////
2572 
2573 // Setup current current thread for event collection.
2574 void JvmtiEventCollector::setup_jvmti_thread_state() {
2575   // set this event collector to be the current one.
2576   JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
2577   // state can only be NULL if the current thread is exiting which
2578   // should not happen since we're trying to configure for event collection
2579   guarantee(state != NULL, "exiting thread called setup_jvmti_thread_state");
2580   if (is_vm_object_alloc_event()) {
2581     _prev = state->get_vm_object_alloc_event_collector();
2582     state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)this);
2583   } else if (is_dynamic_code_event()) {
2584     _prev = state->get_dynamic_code_event_collector();
2585     state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)this);
2586   }


< prev index next >