< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.inline.hpp"
  27 #include "classfile/moduleEntry.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "code/pcDesc.hpp"
  31 #include "code/scopeDesc.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "jvmtifiles/jvmtiEnv.hpp"
  34 #include "logging/log.hpp"
  35 #include "logging/logStream.hpp"
  36 #include "memory/allocation.inline.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "memory/universe.hpp"
  39 #include "oops/objArrayKlass.hpp"
  40 #include "oops/objArrayOop.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "prims/jvmtiCodeBlobEvents.hpp"
  43 #include "prims/jvmtiEventController.hpp"
  44 #include "prims/jvmtiEventController.inline.hpp"
  45 #include "prims/jvmtiExport.hpp"
  46 #include "prims/jvmtiImpl.hpp"
  47 #include "prims/jvmtiManageCapabilities.hpp"
  48 #include "prims/jvmtiRawMonitor.hpp"
  49 #include "prims/jvmtiRedefineClasses.hpp"
  50 #include "prims/jvmtiTagMap.hpp"
  51 #include "prims/jvmtiThreadState.inline.hpp"
  52 #include "runtime/arguments.hpp"
  53 #include "runtime/fieldDescriptor.inline.hpp"
  54 #include "runtime/handles.inline.hpp"
  55 #include "runtime/interfaceSupport.inline.hpp"
  56 #include "runtime/javaCalls.hpp"
  57 #include "runtime/jniHandles.inline.hpp"
  58 #include "runtime/objectMonitor.hpp"


 366           return JNI_EVERSION;  // unsupported minor version number
 367       }
 368       break;
 369     case 9:
 370       switch (minor) {
 371         case 0:  // version 9.0.<micro> is recognized
 372           break;
 373         default:
 374           return JNI_EVERSION;  // unsupported minor version number
 375       }
 376       break;
 377     case 11:
 378       switch (minor) {
 379         case 0:  // version 11.0.<micro> is recognized
 380           break;
 381         default:
 382           return JNI_EVERSION;  // unsupported minor version number
 383       }
 384       break;
 385     default:
 386       // Starting from 13 we do not care about minor version anymore
 387       if (major < 13 || major > Abstract_VM_Version::vm_major_version()) {
 388         return JNI_EVERSION;  // unsupported major version number
 389       }
 390   }
 391 
 392   if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) {
 393     JavaThread* current_thread = JavaThread::current();
 394     // transition code: native to VM
 395     ThreadInVMfromNative __tiv(current_thread);
 396     VM_ENTRY_BASE(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread)
 397     debug_only(VMNativeEntryWrapper __vew;)
 398 
 399     JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
 400     *penv = jvmti_env->jvmti_external();  // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
 401     return JNI_OK;
 402 
 403   } else if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) {
 404     // not live, no thread to transition
 405     JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
 406     *penv = jvmti_env->jvmti_external();  // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
 407     return JNI_OK;
 408 
 409   } else {


2157       record->pcinfo[scope].bcis[stackframe] = sd->bci();
2158       stackframe++;
2159     }
2160     scope++;
2161   }
2162   return record;
2163 }
2164 
2165 void JvmtiExport::post_compiled_method_load(nmethod *nm) {
2166   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
2167     return;
2168   }
2169   JavaThread* thread = JavaThread::current();
2170 
2171   EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
2172                  ("[%s] method compile load event triggered",
2173                  JvmtiTrace::safe_get_thread_name(thread)));
2174 
2175   JvmtiEnvIterator it;
2176   for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2177     post_compiled_method_load(env, nm);























2178   }
2179 }
2180 

2181 // post a COMPILED_METHOD_LOAD event for a given environment
2182 void JvmtiExport::post_compiled_method_load(JvmtiEnv* env, nmethod *nm) {
2183   if (env->phase() == JVMTI_PHASE_PRIMORDIAL || !env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
2184     return;
2185   }
2186   jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
2187   if (callback == NULL) {
2188     return;
2189   }
2190   JavaThread* thread = JavaThread::current();




2191 
2192   EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
2193            ("[%s] method compile load event sent %s.%s  ",
2194             JvmtiTrace::safe_get_thread_name(thread),
2195             (nm->method() == NULL) ? "NULL" : nm->method()->klass_name()->as_C_string(),
2196             (nm->method() == NULL) ? "NULL" : nm->method()->name()->as_C_string()));
2197   ResourceMark rm(thread);
2198   HandleMark hm(thread);
2199 
2200   // Add inlining information
2201   jvmtiCompiledMethodLoadInlineRecord* inlinerecord = create_inline_record(nm);
2202   // Pass inlining information through the void pointer
2203   JvmtiCompiledMethodLoadEventMark jem(thread, nm, inlinerecord);
2204   JvmtiJavaThreadEventTransition jet(thread);
2205   (*callback)(env->jvmti_external(), jem.jni_methodID(),
2206               jem.code_size(), jem.code_data(), jem.map_length(),
2207               jem.map(), jem.compile_info());
2208 }
2209 
2210 void JvmtiExport::post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) {
2211   assert(name != NULL && name[0] != '\0', "sanity check");
2212 
2213   JavaThread* thread = JavaThread::current();
2214   // In theory everyone coming thru here is in_vm but we need to be certain
2215   // because a callee will do a vm->native transition
2216   ThreadInVMfromUnknown __tiv;
2217 
2218   EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
2219                  ("[%s] method dynamic code generated event triggered",
2220                  JvmtiTrace::safe_get_thread_name(thread)));
2221   JvmtiEnvIterator it;
2222   for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2223     if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) {
2224       EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
2225                 ("[%s] dynamic code generated event sent for %s",
2226                 JvmtiTrace::safe_get_thread_name(thread), name));
2227       JvmtiEventMark jem(thread);
2228       JvmtiJavaThreadEventTransition jet(thread);
2229       jint length = (jint)pointer_delta(code_end, code_begin, sizeof(char));
2230       jvmtiEventDynamicCodeGenerated callback = env->callbacks()->DynamicCodeGenerated;
2231       if (callback != NULL) {
2232         (*callback)(env->jvmti_external(), name, (void*)code_begin, length);
2233       }
2234     }
2235   }
2236 }
2237 
2238 void JvmtiExport::post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) {
2239   jvmtiPhase phase = JvmtiEnv::get_phase();
2240   if (phase == JVMTI_PHASE_PRIMORDIAL || phase == JVMTI_PHASE_START) {
2241     post_dynamic_code_generated_internal(name, code_begin, code_end);
2242   } else {
2243     // It may not be safe to post the event from this thread.  Defer all
2244     // postings to the service thread so that it can perform them in a safe
2245     // context and in-order.
2246     MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
2247     JvmtiDeferredEvent event = JvmtiDeferredEvent::dynamic_code_generated_event(
2248         name, code_begin, code_end);
2249     JvmtiDeferredEventQueue::enqueue(event);
2250   }
2251 }
2252 
2253 
2254 // post a DYNAMIC_CODE_GENERATED event for a given environment
2255 // used by GenerateEvents
2256 void JvmtiExport::post_dynamic_code_generated(JvmtiEnv* env, const char *name,
2257                                               const void *code_begin, const void *code_end)
2258 {
2259   JavaThread* thread = JavaThread::current();
2260   EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
2261                  ("[%s] dynamic code generated event triggered (by GenerateEvents)",
2262                   JvmtiTrace::safe_get_thread_name(thread)));
2263   if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) {
2264     EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
2265               ("[%s] dynamic code generated event sent for %s",
2266                JvmtiTrace::safe_get_thread_name(thread), name));




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.inline.hpp"
  27 #include "classfile/moduleEntry.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "code/pcDesc.hpp"
  31 #include "code/scopeDesc.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "jvmtifiles/jvmtiEnv.hpp"
  34 #include "logging/log.hpp"
  35 #include "logging/logStream.hpp"
  36 #include "memory/allocation.inline.hpp"
  37 #include "memory/resourceArea.hpp"

  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/objArrayOop.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "prims/jvmtiCodeBlobEvents.hpp"
  42 #include "prims/jvmtiEventController.hpp"
  43 #include "prims/jvmtiEventController.inline.hpp"
  44 #include "prims/jvmtiExport.hpp"
  45 #include "prims/jvmtiImpl.hpp"
  46 #include "prims/jvmtiManageCapabilities.hpp"
  47 #include "prims/jvmtiRawMonitor.hpp"
  48 #include "prims/jvmtiRedefineClasses.hpp"
  49 #include "prims/jvmtiTagMap.hpp"
  50 #include "prims/jvmtiThreadState.inline.hpp"
  51 #include "runtime/arguments.hpp"
  52 #include "runtime/fieldDescriptor.inline.hpp"
  53 #include "runtime/handles.inline.hpp"
  54 #include "runtime/interfaceSupport.inline.hpp"
  55 #include "runtime/javaCalls.hpp"
  56 #include "runtime/jniHandles.inline.hpp"
  57 #include "runtime/objectMonitor.hpp"


 365           return JNI_EVERSION;  // unsupported minor version number
 366       }
 367       break;
 368     case 9:
 369       switch (minor) {
 370         case 0:  // version 9.0.<micro> is recognized
 371           break;
 372         default:
 373           return JNI_EVERSION;  // unsupported minor version number
 374       }
 375       break;
 376     case 11:
 377       switch (minor) {
 378         case 0:  // version 11.0.<micro> is recognized
 379           break;
 380         default:
 381           return JNI_EVERSION;  // unsupported minor version number
 382       }
 383       break;
 384     default:
 385       return JNI_EVERSION;  // unsupported major version number



 386   }
 387 
 388   if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) {
 389     JavaThread* current_thread = JavaThread::current();
 390     // transition code: native to VM
 391     ThreadInVMfromNative __tiv(current_thread);
 392     VM_ENTRY_BASE(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread)
 393     debug_only(VMNativeEntryWrapper __vew;)
 394 
 395     JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
 396     *penv = jvmti_env->jvmti_external();  // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
 397     return JNI_OK;
 398 
 399   } else if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) {
 400     // not live, no thread to transition
 401     JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
 402     *penv = jvmti_env->jvmti_external();  // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
 403     return JNI_OK;
 404 
 405   } else {


2153       record->pcinfo[scope].bcis[stackframe] = sd->bci();
2154       stackframe++;
2155     }
2156     scope++;
2157   }
2158   return record;
2159 }
2160 
2161 void JvmtiExport::post_compiled_method_load(nmethod *nm) {
2162   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
2163     return;
2164   }
2165   JavaThread* thread = JavaThread::current();
2166 
2167   EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
2168                  ("[%s] method compile load event triggered",
2169                  JvmtiTrace::safe_get_thread_name(thread)));
2170 
2171   JvmtiEnvIterator it;
2172   for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2173     if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
2174       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
2175         continue;
2176       }
2177       EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
2178                 ("[%s] class compile method load event sent %s.%s  ",
2179                 JvmtiTrace::safe_get_thread_name(thread),
2180                 (nm->method() == NULL) ? "NULL" : nm->method()->klass_name()->as_C_string(),
2181                 (nm->method() == NULL) ? "NULL" : nm->method()->name()->as_C_string()));
2182       ResourceMark rm(thread);
2183       HandleMark hm(thread);
2184 
2185       // Add inlining information
2186       jvmtiCompiledMethodLoadInlineRecord* inlinerecord = create_inline_record(nm);
2187       // Pass inlining information through the void pointer
2188       JvmtiCompiledMethodLoadEventMark jem(thread, nm, inlinerecord);
2189       JvmtiJavaThreadEventTransition jet(thread);
2190       jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
2191       if (callback != NULL) {
2192         (*callback)(env->jvmti_external(), jem.jni_methodID(),
2193                     jem.code_size(), jem.code_data(), jem.map_length(),
2194                     jem.map(), jem.compile_info());
2195       }
2196     }
2197   }
2198 }
2199 
2200 
2201 // post a COMPILED_METHOD_LOAD event for a given environment
2202 void JvmtiExport::post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length,
2203                                             const void *code_begin, const jint map_length,
2204                                             const jvmtiAddrLocationMap* map)
2205 {
2206   if (env->phase() <= JVMTI_PHASE_PRIMORDIAL) {

2207     return;
2208   }
2209   JavaThread* thread = JavaThread::current();
2210   EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
2211                  ("[%s] method compile load event triggered (by GenerateEvents)",
2212                  JvmtiTrace::safe_get_thread_name(thread)));
2213   if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
2214 
2215     EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
2216               ("[%s] class compile method load event sent (by GenerateEvents), jmethodID=" PTR_FORMAT,
2217                JvmtiTrace::safe_get_thread_name(thread), p2i(method)));
2218 
2219     JvmtiEventMark jem(thread);
2220     JvmtiJavaThreadEventTransition jet(thread);
2221     jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
2222     if (callback != NULL) {
2223       (*callback)(env->jvmti_external(), method,
2224                   length, code_begin, map_length,
2225                   map, NULL);
2226     }
2227   }



2228 }
2229 
2230 void JvmtiExport::post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) {
2231   assert(name != NULL && name[0] != '\0', "sanity check");
2232 
2233   JavaThread* thread = JavaThread::current();
2234   // In theory everyone coming thru here is in_vm but we need to be certain
2235   // because a callee will do a vm->native transition
2236   ThreadInVMfromUnknown __tiv;
2237 
2238   EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
2239                  ("[%s] method dynamic code generated event triggered",
2240                  JvmtiTrace::safe_get_thread_name(thread)));
2241   JvmtiEnvIterator it;
2242   for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2243     if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) {
2244       EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
2245                 ("[%s] dynamic code generated event sent for %s",
2246                 JvmtiTrace::safe_get_thread_name(thread), name));
2247       JvmtiEventMark jem(thread);
2248       JvmtiJavaThreadEventTransition jet(thread);
2249       jint length = (jint)pointer_delta(code_end, code_begin, sizeof(char));
2250       jvmtiEventDynamicCodeGenerated callback = env->callbacks()->DynamicCodeGenerated;
2251       if (callback != NULL) {
2252         (*callback)(env->jvmti_external(), name, (void*)code_begin, length);
2253       }
2254     }
2255   }
2256 }
2257 
2258 void JvmtiExport::post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) {
2259   jvmtiPhase phase = JvmtiEnv::get_phase();
2260   if (phase == JVMTI_PHASE_PRIMORDIAL || phase == JVMTI_PHASE_START) {
2261     post_dynamic_code_generated_internal(name, code_begin, code_end);
2262   } else {
2263     // It may not be safe to post the event from this thread.  Defer all
2264     // postings to the service thread so that it can perform them in a safe
2265     // context and in-order.
2266     MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
2267     JvmtiDeferredEvent event = JvmtiDeferredEvent::dynamic_code_generated_event(
2268         name, code_begin, code_end);
2269     JvmtiDeferredEventQueue::enqueue(event);
2270   }
2271 }
2272 
2273 
2274 // post a DYNAMIC_CODE_GENERATED event for a given environment
2275 // used by GenerateEvents
2276 void JvmtiExport::post_dynamic_code_generated(JvmtiEnv* env, const char *name,
2277                                               const void *code_begin, const void *code_end)
2278 {
2279   JavaThread* thread = JavaThread::current();
2280   EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
2281                  ("[%s] dynamic code generated event triggered (by GenerateEvents)",
2282                   JvmtiTrace::safe_get_thread_name(thread)));
2283   if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) {
2284     EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
2285               ("[%s] dynamic code generated event sent for %s",
2286                JvmtiTrace::safe_get_thread_name(thread), name));


< prev index next >