src/share/vm/prims/jvmtiExport.cpp

Fri, 25 Jan 2013 10:04:08 -0500

author
zgu
date
Fri, 25 Jan 2013 10:04:08 -0500
changeset 4492
8b46b0196eb0
parent 4405
0c8717a92b2d
child 4544
3c9bc17b9403
permissions
-rw-r--r--

8000692: Remove old KERNEL code
Summary: Removed depreciated kernel VM source code from hotspot VM
Reviewed-by: dholmes, acorn

duke@435 1 /*
zgu@4492 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/systemDictionary.hpp"
stefank@2314 27 #include "code/nmethod.hpp"
stefank@2314 28 #include "code/pcDesc.hpp"
stefank@2314 29 #include "code/scopeDesc.hpp"
stefank@2314 30 #include "interpreter/interpreter.hpp"
stefank@2314 31 #include "jvmtifiles/jvmtiEnv.hpp"
stefank@2314 32 #include "memory/resourceArea.hpp"
stefank@2314 33 #include "oops/objArrayKlass.hpp"
stefank@2314 34 #include "oops/objArrayOop.hpp"
stefank@2314 35 #include "prims/jvmtiCodeBlobEvents.hpp"
stefank@2314 36 #include "prims/jvmtiEventController.hpp"
stefank@2314 37 #include "prims/jvmtiEventController.inline.hpp"
stefank@2314 38 #include "prims/jvmtiExport.hpp"
stefank@2314 39 #include "prims/jvmtiImpl.hpp"
stefank@2314 40 #include "prims/jvmtiManageCapabilities.hpp"
stefank@2314 41 #include "prims/jvmtiRawMonitor.hpp"
stefank@2314 42 #include "prims/jvmtiTagMap.hpp"
stefank@2314 43 #include "prims/jvmtiThreadState.inline.hpp"
stefank@2314 44 #include "runtime/arguments.hpp"
stefank@2314 45 #include "runtime/handles.hpp"
stefank@2314 46 #include "runtime/interfaceSupport.hpp"
stefank@2314 47 #include "runtime/objectMonitor.hpp"
stefank@2314 48 #include "runtime/objectMonitor.inline.hpp"
stefank@2314 49 #include "runtime/thread.hpp"
stefank@2314 50 #include "runtime/vframe.hpp"
stefank@2314 51 #include "services/attachListener.hpp"
stefank@2314 52 #include "services/serviceUtil.hpp"
stefank@2314 53 #ifndef SERIALGC
stefank@2314 54 #include "gc_implementation/parallelScavenge/psMarkSweep.hpp"
stefank@2314 55 #endif
duke@435 56
duke@435 57 #ifdef JVMTI_TRACE
duke@435 58 #define EVT_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_SENT) != 0) { SafeResourceMark rm; tty->print_cr out; }
duke@435 59 #define EVT_TRIG_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_TRIGGER) != 0) { SafeResourceMark rm; tty->print_cr out; }
duke@435 60 #else
duke@435 61 #define EVT_TRIG_TRACE(evt,out)
duke@435 62 #define EVT_TRACE(evt,out)
duke@435 63 #endif
duke@435 64
duke@435 65 ///////////////////////////////////////////////////////////////
duke@435 66 //
duke@435 67 // JvmtiEventTransition
duke@435 68 //
duke@435 69 // TO DO --
duke@435 70 // more handle purging
duke@435 71
duke@435 72 // Use this for JavaThreads and state is _thread_in_vm.
duke@435 73 class JvmtiJavaThreadEventTransition : StackObj {
duke@435 74 private:
duke@435 75 ResourceMark _rm;
duke@435 76 ThreadToNativeFromVM _transition;
duke@435 77 HandleMark _hm;
duke@435 78
duke@435 79 public:
duke@435 80 JvmtiJavaThreadEventTransition(JavaThread *thread) :
duke@435 81 _rm(),
duke@435 82 _transition(thread),
duke@435 83 _hm(thread) {};
duke@435 84 };
duke@435 85
duke@435 86 // For JavaThreads which are not in _thread_in_vm state
duke@435 87 // and other system threads use this.
duke@435 88 class JvmtiThreadEventTransition : StackObj {
duke@435 89 private:
duke@435 90 ResourceMark _rm;
duke@435 91 HandleMark _hm;
duke@435 92 JavaThreadState _saved_state;
duke@435 93 JavaThread *_jthread;
duke@435 94
duke@435 95 public:
duke@435 96 JvmtiThreadEventTransition(Thread *thread) : _rm(), _hm() {
duke@435 97 if (thread->is_Java_thread()) {
duke@435 98 _jthread = (JavaThread *)thread;
duke@435 99 _saved_state = _jthread->thread_state();
duke@435 100 if (_saved_state == _thread_in_Java) {
duke@435 101 ThreadStateTransition::transition_from_java(_jthread, _thread_in_native);
duke@435 102 } else {
duke@435 103 ThreadStateTransition::transition(_jthread, _saved_state, _thread_in_native);
duke@435 104 }
duke@435 105 } else {
duke@435 106 _jthread = NULL;
duke@435 107 }
duke@435 108 }
duke@435 109
duke@435 110 ~JvmtiThreadEventTransition() {
duke@435 111 if (_jthread != NULL)
duke@435 112 ThreadStateTransition::transition_from_native(_jthread, _saved_state);
duke@435 113 }
duke@435 114 };
duke@435 115
duke@435 116
duke@435 117 ///////////////////////////////////////////////////////////////
duke@435 118 //
duke@435 119 // JvmtiEventMark
duke@435 120 //
duke@435 121
duke@435 122 class JvmtiEventMark : public StackObj {
duke@435 123 private:
duke@435 124 JavaThread *_thread;
duke@435 125 JNIEnv* _jni_env;
duke@435 126 bool _exception_detected;
duke@435 127 bool _exception_caught;
duke@435 128 #if 0
duke@435 129 JNIHandleBlock* _hblock;
duke@435 130 #endif
duke@435 131
duke@435 132 public:
duke@435 133 JvmtiEventMark(JavaThread *thread) : _thread(thread),
duke@435 134 _jni_env(thread->jni_environment()) {
duke@435 135 #if 0
duke@435 136 _hblock = thread->active_handles();
duke@435 137 _hblock->clear_thoroughly(); // so we can be safe
duke@435 138 #else
duke@435 139 // we want to use the code above - but that needs the JNIHandle changes - later...
duke@435 140 // for now, steal JNI push local frame code
duke@435 141 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 142 // we are before an event.
duke@435 143 // Save current jvmti thread exception state.
duke@435 144 if (state != NULL) {
duke@435 145 _exception_detected = state->is_exception_detected();
duke@435 146 _exception_caught = state->is_exception_caught();
duke@435 147 } else {
duke@435 148 _exception_detected = false;
duke@435 149 _exception_caught = false;
duke@435 150 }
duke@435 151
duke@435 152 JNIHandleBlock* old_handles = thread->active_handles();
duke@435 153 JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread);
duke@435 154 assert(new_handles != NULL, "should not be NULL");
duke@435 155 new_handles->set_pop_frame_link(old_handles);
duke@435 156 thread->set_active_handles(new_handles);
duke@435 157 #endif
duke@435 158 assert(thread == JavaThread::current(), "thread must be current!");
duke@435 159 thread->frame_anchor()->make_walkable(thread);
duke@435 160 };
duke@435 161
duke@435 162 ~JvmtiEventMark() {
duke@435 163 #if 0
duke@435 164 _hblock->clear(); // for consistency with future correct behavior
duke@435 165 #else
duke@435 166 // we want to use the code above - but that needs the JNIHandle changes - later...
duke@435 167 // for now, steal JNI pop local frame code
duke@435 168 JNIHandleBlock* old_handles = _thread->active_handles();
duke@435 169 JNIHandleBlock* new_handles = old_handles->pop_frame_link();
duke@435 170 assert(new_handles != NULL, "should not be NULL");
duke@435 171 _thread->set_active_handles(new_handles);
duke@435 172 // Note that we set the pop_frame_link to NULL explicitly, otherwise
duke@435 173 // the release_block call will release the blocks.
duke@435 174 old_handles->set_pop_frame_link(NULL);
duke@435 175 JNIHandleBlock::release_block(old_handles, _thread); // may block
duke@435 176 #endif
duke@435 177
duke@435 178 JvmtiThreadState* state = _thread->jvmti_thread_state();
duke@435 179 // we are continuing after an event.
duke@435 180 if (state != NULL) {
duke@435 181 // Restore the jvmti thread exception state.
duke@435 182 if (_exception_detected) {
duke@435 183 state->set_exception_detected();
duke@435 184 }
duke@435 185 if (_exception_caught) {
duke@435 186 state->set_exception_caught();
duke@435 187 }
duke@435 188 }
duke@435 189 }
duke@435 190
duke@435 191 #if 0
duke@435 192 jobject to_jobject(oop obj) { return obj == NULL? NULL : _hblock->allocate_handle_fast(obj); }
duke@435 193 #else
duke@435 194 // we want to use the code above - but that needs the JNIHandle changes - later...
duke@435 195 // for now, use regular make_local
duke@435 196 jobject to_jobject(oop obj) { return JNIHandles::make_local(_thread,obj); }
duke@435 197 #endif
duke@435 198
hseigel@4278 199 jclass to_jclass(Klass* klass) { return (klass == NULL ? NULL : (jclass)to_jobject(klass->java_mirror())); }
duke@435 200
duke@435 201 jmethodID to_jmethodID(methodHandle method) { return method->jmethod_id(); }
duke@435 202
duke@435 203 JNIEnv* jni_env() { return _jni_env; }
duke@435 204 };
duke@435 205
duke@435 206 class JvmtiThreadEventMark : public JvmtiEventMark {
duke@435 207 private:
duke@435 208 jthread _jt;
duke@435 209
duke@435 210 public:
duke@435 211 JvmtiThreadEventMark(JavaThread *thread) :
duke@435 212 JvmtiEventMark(thread) {
duke@435 213 _jt = (jthread)(to_jobject(thread->threadObj()));
duke@435 214 };
duke@435 215 jthread jni_thread() { return _jt; }
duke@435 216 };
duke@435 217
duke@435 218 class JvmtiClassEventMark : public JvmtiThreadEventMark {
duke@435 219 private:
duke@435 220 jclass _jc;
duke@435 221
duke@435 222 public:
coleenp@4037 223 JvmtiClassEventMark(JavaThread *thread, Klass* klass) :
duke@435 224 JvmtiThreadEventMark(thread) {
duke@435 225 _jc = to_jclass(klass);
duke@435 226 };
duke@435 227 jclass jni_class() { return _jc; }
duke@435 228 };
duke@435 229
duke@435 230 class JvmtiMethodEventMark : public JvmtiThreadEventMark {
duke@435 231 private:
duke@435 232 jmethodID _mid;
duke@435 233
duke@435 234 public:
duke@435 235 JvmtiMethodEventMark(JavaThread *thread, methodHandle method) :
duke@435 236 JvmtiThreadEventMark(thread),
duke@435 237 _mid(to_jmethodID(method)) {};
duke@435 238 jmethodID jni_methodID() { return _mid; }
duke@435 239 };
duke@435 240
duke@435 241 class JvmtiLocationEventMark : public JvmtiMethodEventMark {
duke@435 242 private:
duke@435 243 jlocation _loc;
duke@435 244
duke@435 245 public:
duke@435 246 JvmtiLocationEventMark(JavaThread *thread, methodHandle method, address location) :
duke@435 247 JvmtiMethodEventMark(thread, method),
duke@435 248 _loc(location - method->code_base()) {};
duke@435 249 jlocation location() { return _loc; }
duke@435 250 };
duke@435 251
duke@435 252 class JvmtiExceptionEventMark : public JvmtiLocationEventMark {
duke@435 253 private:
duke@435 254 jobject _exc;
duke@435 255
duke@435 256 public:
duke@435 257 JvmtiExceptionEventMark(JavaThread *thread, methodHandle method, address location, Handle exception) :
duke@435 258 JvmtiLocationEventMark(thread, method, location),
duke@435 259 _exc(to_jobject(exception())) {};
duke@435 260 jobject exception() { return _exc; }
duke@435 261 };
duke@435 262
duke@435 263 class JvmtiClassFileLoadEventMark : public JvmtiThreadEventMark {
duke@435 264 private:
duke@435 265 const char *_class_name;
duke@435 266 jobject _jloader;
duke@435 267 jobject _protection_domain;
duke@435 268 jclass _class_being_redefined;
duke@435 269
duke@435 270 public:
coleenp@2497 271 JvmtiClassFileLoadEventMark(JavaThread *thread, Symbol* name,
duke@435 272 Handle class_loader, Handle prot_domain, KlassHandle *class_being_redefined) : JvmtiThreadEventMark(thread) {
coleenp@2497 273 _class_name = name != NULL? name->as_utf8() : NULL;
duke@435 274 _jloader = (jobject)to_jobject(class_loader());
duke@435 275 _protection_domain = (jobject)to_jobject(prot_domain());
duke@435 276 if (class_being_redefined == NULL) {
duke@435 277 _class_being_redefined = NULL;
duke@435 278 } else {
duke@435 279 _class_being_redefined = (jclass)to_jclass((*class_being_redefined)());
duke@435 280 }
duke@435 281 };
duke@435 282 const char *class_name() {
duke@435 283 return _class_name;
duke@435 284 }
duke@435 285 jobject jloader() {
duke@435 286 return _jloader;
duke@435 287 }
duke@435 288 jobject protection_domain() {
duke@435 289 return _protection_domain;
duke@435 290 }
duke@435 291 jclass class_being_redefined() {
duke@435 292 return _class_being_redefined;
duke@435 293 }
duke@435 294 };
duke@435 295
duke@435 296 //////////////////////////////////////////////////////////////////////////////
duke@435 297
duke@435 298 int JvmtiExport::_field_access_count = 0;
duke@435 299 int JvmtiExport::_field_modification_count = 0;
duke@435 300
duke@435 301 bool JvmtiExport::_can_access_local_variables = false;
duke@435 302 bool JvmtiExport::_can_hotswap_or_post_breakpoint = false;
duke@435 303 bool JvmtiExport::_can_modify_any_class = false;
duke@435 304 bool JvmtiExport::_can_walk_any_space = false;
duke@435 305
duke@435 306 bool JvmtiExport::_has_redefined_a_class = false;
duke@435 307 bool JvmtiExport::_all_dependencies_are_recorded = false;
duke@435 308
duke@435 309 //
duke@435 310 // field access management
duke@435 311 //
duke@435 312
duke@435 313 // interpreter generator needs the address of the counter
duke@435 314 address JvmtiExport::get_field_access_count_addr() {
duke@435 315 // We don't grab a lock because we don't want to
duke@435 316 // serialize field access between all threads. This means that a
duke@435 317 // thread on another processor can see the wrong count value and
duke@435 318 // may either miss making a needed call into post_field_access()
duke@435 319 // or will make an unneeded call into post_field_access(). We pay
duke@435 320 // this price to avoid slowing down the VM when we aren't watching
duke@435 321 // field accesses.
duke@435 322 // Other access/mutation safe by virtue of being in VM state.
duke@435 323 return (address)(&_field_access_count);
duke@435 324 }
duke@435 325
duke@435 326 //
duke@435 327 // field modification management
duke@435 328 //
duke@435 329
duke@435 330 // interpreter generator needs the address of the counter
duke@435 331 address JvmtiExport::get_field_modification_count_addr() {
duke@435 332 // We don't grab a lock because we don't
duke@435 333 // want to serialize field modification between all threads. This
duke@435 334 // means that a thread on another processor can see the wrong
duke@435 335 // count value and may either miss making a needed call into
duke@435 336 // post_field_modification() or will make an unneeded call into
duke@435 337 // post_field_modification(). We pay this price to avoid slowing
duke@435 338 // down the VM when we aren't watching field modifications.
duke@435 339 // Other access/mutation safe by virtue of being in VM state.
duke@435 340 return (address)(&_field_modification_count);
duke@435 341 }
duke@435 342
duke@435 343
duke@435 344 ///////////////////////////////////////////////////////////////
duke@435 345 // Functions needed by java.lang.instrument for starting up javaagent.
duke@435 346 ///////////////////////////////////////////////////////////////
duke@435 347
duke@435 348 jint
duke@435 349 JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) {
dcubed@1556 350 // The JVMTI_VERSION_INTERFACE_JVMTI part of the version number
dcubed@1556 351 // has already been validated in JNI GetEnv().
dcubed@1556 352 int major, minor, micro;
dcubed@1556 353
dcubed@1556 354 // micro version doesn't matter here (yet?)
dcubed@1556 355 decode_version_values(version, &major, &minor, &micro);
dcubed@1556 356 switch (major) {
kamg@2330 357 case 1:
dcubed@1556 358 switch (minor) {
kamg@2330 359 case 0: // version 1.0.<micro> is recognized
kamg@2330 360 case 1: // version 1.1.<micro> is recognized
kamg@2330 361 case 2: // version 1.2.<micro> is recognized
dcubed@1556 362 break;
dcubed@1556 363
kamg@2330 364 default:
dcubed@1556 365 return JNI_EVERSION; // unsupported minor version number
dcubed@1556 366 }
dcubed@1556 367 break;
kamg@2330 368 default:
dcubed@1556 369 return JNI_EVERSION; // unsupported major version number
dcubed@1556 370 }
duke@435 371
duke@435 372 if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) {
duke@435 373 JavaThread* current_thread = (JavaThread*) ThreadLocalStorage::thread();
duke@435 374 // transition code: native to VM
duke@435 375 ThreadInVMfromNative __tiv(current_thread);
never@3241 376 VM_ENTRY_BASE(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread)
duke@435 377 debug_only(VMNativeEntryWrapper __vew;)
duke@435 378
dcubed@1556 379 JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
duke@435 380 *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
duke@435 381 return JNI_OK;
duke@435 382
duke@435 383 } else if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) {
duke@435 384 // not live, no thread to transition
dcubed@1556 385 JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
duke@435 386 *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
duke@435 387 return JNI_OK;
duke@435 388
duke@435 389 } else {
duke@435 390 // Called at the wrong time
duke@435 391 *penv = NULL;
duke@435 392 return JNI_EDETACHED;
duke@435 393 }
duke@435 394 }
duke@435 395
dcubed@1556 396
dcubed@1556 397 void
dcubed@1556 398 JvmtiExport::decode_version_values(jint version, int * major, int * minor,
dcubed@1556 399 int * micro) {
dcubed@1556 400 *major = (version & JVMTI_VERSION_MASK_MAJOR) >> JVMTI_VERSION_SHIFT_MAJOR;
dcubed@1556 401 *minor = (version & JVMTI_VERSION_MASK_MINOR) >> JVMTI_VERSION_SHIFT_MINOR;
dcubed@1556 402 *micro = (version & JVMTI_VERSION_MASK_MICRO) >> JVMTI_VERSION_SHIFT_MICRO;
dcubed@1556 403 }
dcubed@1556 404
duke@435 405 void JvmtiExport::enter_primordial_phase() {
duke@435 406 JvmtiEnvBase::set_phase(JVMTI_PHASE_PRIMORDIAL);
duke@435 407 }
duke@435 408
duke@435 409 void JvmtiExport::enter_start_phase() {
duke@435 410 JvmtiManageCapabilities::recompute_always_capabilities();
duke@435 411 JvmtiEnvBase::set_phase(JVMTI_PHASE_START);
duke@435 412 }
duke@435 413
duke@435 414 void JvmtiExport::enter_onload_phase() {
duke@435 415 JvmtiEnvBase::set_phase(JVMTI_PHASE_ONLOAD);
duke@435 416 }
duke@435 417
duke@435 418 void JvmtiExport::enter_live_phase() {
duke@435 419 JvmtiEnvBase::set_phase(JVMTI_PHASE_LIVE);
duke@435 420 }
duke@435 421
duke@435 422 //
duke@435 423 // JVMTI events that the VM posts to the debugger and also startup agent
duke@435 424 // and call the agent's premain() for java.lang.instrument.
duke@435 425 //
duke@435 426
duke@435 427 void JvmtiExport::post_vm_start() {
duke@435 428 EVT_TRIG_TRACE(JVMTI_EVENT_VM_START, ("JVMTI Trg VM start event triggered" ));
duke@435 429
duke@435 430 // can now enable some events
duke@435 431 JvmtiEventController::vm_start();
duke@435 432
duke@435 433 JvmtiEnvIterator it;
duke@435 434 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 435 if (env->is_enabled(JVMTI_EVENT_VM_START)) {
duke@435 436 EVT_TRACE(JVMTI_EVENT_VM_START, ("JVMTI Evt VM start event sent" ));
duke@435 437
duke@435 438 JavaThread *thread = JavaThread::current();
duke@435 439 JvmtiThreadEventMark jem(thread);
duke@435 440 JvmtiJavaThreadEventTransition jet(thread);
duke@435 441 jvmtiEventVMStart callback = env->callbacks()->VMStart;
duke@435 442 if (callback != NULL) {
duke@435 443 (*callback)(env->jvmti_external(), jem.jni_env());
duke@435 444 }
duke@435 445 }
duke@435 446 }
duke@435 447 }
duke@435 448
duke@435 449
duke@435 450 void JvmtiExport::post_vm_initialized() {
duke@435 451 EVT_TRIG_TRACE(JVMTI_EVENT_VM_INIT, ("JVMTI Trg VM init event triggered" ));
duke@435 452
duke@435 453 // can now enable events
duke@435 454 JvmtiEventController::vm_init();
duke@435 455
duke@435 456 JvmtiEnvIterator it;
duke@435 457 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 458 if (env->is_enabled(JVMTI_EVENT_VM_INIT)) {
duke@435 459 EVT_TRACE(JVMTI_EVENT_VM_INIT, ("JVMTI Evt VM init event sent" ));
duke@435 460
duke@435 461 JavaThread *thread = JavaThread::current();
duke@435 462 JvmtiThreadEventMark jem(thread);
duke@435 463 JvmtiJavaThreadEventTransition jet(thread);
duke@435 464 jvmtiEventVMInit callback = env->callbacks()->VMInit;
duke@435 465 if (callback != NULL) {
duke@435 466 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
duke@435 467 }
duke@435 468 }
duke@435 469 }
duke@435 470 }
duke@435 471
duke@435 472
duke@435 473 void JvmtiExport::post_vm_death() {
duke@435 474 EVT_TRIG_TRACE(JVMTI_EVENT_VM_DEATH, ("JVMTI Trg VM death event triggered" ));
duke@435 475
duke@435 476 JvmtiEnvIterator it;
duke@435 477 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 478 if (env->is_enabled(JVMTI_EVENT_VM_DEATH)) {
duke@435 479 EVT_TRACE(JVMTI_EVENT_VM_DEATH, ("JVMTI Evt VM death event sent" ));
duke@435 480
duke@435 481 JavaThread *thread = JavaThread::current();
duke@435 482 JvmtiEventMark jem(thread);
duke@435 483 JvmtiJavaThreadEventTransition jet(thread);
duke@435 484 jvmtiEventVMDeath callback = env->callbacks()->VMDeath;
duke@435 485 if (callback != NULL) {
duke@435 486 (*callback)(env->jvmti_external(), jem.jni_env());
duke@435 487 }
duke@435 488 }
duke@435 489 }
duke@435 490
duke@435 491 JvmtiEnvBase::set_phase(JVMTI_PHASE_DEAD);
duke@435 492 JvmtiEventController::vm_death();
duke@435 493 }
duke@435 494
duke@435 495 char**
duke@435 496 JvmtiExport::get_all_native_method_prefixes(int* count_ptr) {
duke@435 497 // Have to grab JVMTI thread state lock to be sure environment doesn't
duke@435 498 // go away while we iterate them. No locks during VM bring-up.
duke@435 499 if (Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint()) {
duke@435 500 return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr);
duke@435 501 } else {
duke@435 502 MutexLocker mu(JvmtiThreadState_lock);
duke@435 503 return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr);
duke@435 504 }
duke@435 505 }
duke@435 506
duke@435 507 class JvmtiClassFileLoadHookPoster : public StackObj {
duke@435 508 private:
coleenp@2497 509 Symbol* _h_name;
duke@435 510 Handle _class_loader;
duke@435 511 Handle _h_protection_domain;
duke@435 512 unsigned char ** _data_ptr;
duke@435 513 unsigned char ** _end_ptr;
duke@435 514 JavaThread * _thread;
duke@435 515 jint _curr_len;
duke@435 516 unsigned char * _curr_data;
duke@435 517 JvmtiEnv * _curr_env;
duke@435 518 jint * _cached_length_ptr;
duke@435 519 unsigned char ** _cached_data_ptr;
duke@435 520 JvmtiThreadState * _state;
duke@435 521 KlassHandle * _h_class_being_redefined;
duke@435 522 JvmtiClassLoadKind _load_kind;
duke@435 523
duke@435 524 public:
coleenp@2497 525 inline JvmtiClassFileLoadHookPoster(Symbol* h_name, Handle class_loader,
duke@435 526 Handle h_protection_domain,
duke@435 527 unsigned char **data_ptr, unsigned char **end_ptr,
duke@435 528 unsigned char **cached_data_ptr,
duke@435 529 jint *cached_length_ptr) {
duke@435 530 _h_name = h_name;
duke@435 531 _class_loader = class_loader;
duke@435 532 _h_protection_domain = h_protection_domain;
duke@435 533 _data_ptr = data_ptr;
duke@435 534 _end_ptr = end_ptr;
duke@435 535 _thread = JavaThread::current();
duke@435 536 _curr_len = *end_ptr - *data_ptr;
duke@435 537 _curr_data = *data_ptr;
duke@435 538 _curr_env = NULL;
duke@435 539 _cached_length_ptr = cached_length_ptr;
duke@435 540 _cached_data_ptr = cached_data_ptr;
duke@435 541
duke@435 542 _state = _thread->jvmti_thread_state();
duke@435 543 if (_state != NULL) {
duke@435 544 _h_class_being_redefined = _state->get_class_being_redefined();
duke@435 545 _load_kind = _state->get_class_load_kind();
duke@435 546 // Clear class_being_redefined flag here. The action
duke@435 547 // from agent handler could generate a new class file load
duke@435 548 // hook event and if it is not cleared the new event generated
duke@435 549 // from regular class file load could have this stale redefined
duke@435 550 // class handle info.
duke@435 551 _state->clear_class_being_redefined();
duke@435 552 } else {
duke@435 553 // redefine and retransform will always set the thread state
duke@435 554 _h_class_being_redefined = (KlassHandle *) NULL;
duke@435 555 _load_kind = jvmti_class_load_kind_load;
duke@435 556 }
duke@435 557 }
duke@435 558
duke@435 559 void post() {
duke@435 560 // EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
duke@435 561 // ("JVMTI [%s] class file load hook event triggered",
duke@435 562 // JvmtiTrace::safe_get_thread_name(_thread)));
duke@435 563 post_all_envs();
duke@435 564 copy_modified_data();
duke@435 565 }
duke@435 566
duke@435 567 private:
duke@435 568 void post_all_envs() {
duke@435 569 if (_load_kind != jvmti_class_load_kind_retransform) {
duke@435 570 // for class load and redefine,
duke@435 571 // call the non-retransformable agents
duke@435 572 JvmtiEnvIterator it;
duke@435 573 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 574 if (!env->is_retransformable() && env->is_enabled(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK)) {
duke@435 575 // non-retransformable agents cannot retransform back,
duke@435 576 // so no need to cache the original class file bytes
duke@435 577 post_to_env(env, false);
duke@435 578 }
duke@435 579 }
duke@435 580 }
duke@435 581 JvmtiEnvIterator it;
duke@435 582 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 583 // retransformable agents get all events
duke@435 584 if (env->is_retransformable() && env->is_enabled(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK)) {
duke@435 585 // retransformable agents need to cache the original class file
duke@435 586 // bytes if changes are made via the ClassFileLoadHook
duke@435 587 post_to_env(env, true);
duke@435 588 }
duke@435 589 }
duke@435 590 }
duke@435 591
duke@435 592 void post_to_env(JvmtiEnv* env, bool caching_needed) {
duke@435 593 unsigned char *new_data = NULL;
duke@435 594 jint new_len = 0;
duke@435 595 // EVT_TRACE(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
duke@435 596 // ("JVMTI [%s] class file load hook event sent %s data_ptr = %d, data_len = %d",
duke@435 597 // JvmtiTrace::safe_get_thread_name(_thread),
coleenp@2497 598 // _h_name == NULL ? "NULL" : _h_name->as_utf8(),
duke@435 599 // _curr_data, _curr_len ));
duke@435 600 JvmtiClassFileLoadEventMark jem(_thread, _h_name, _class_loader,
duke@435 601 _h_protection_domain,
duke@435 602 _h_class_being_redefined);
duke@435 603 JvmtiJavaThreadEventTransition jet(_thread);
duke@435 604 JNIEnv* jni_env = (JvmtiEnv::get_phase() == JVMTI_PHASE_PRIMORDIAL)?
duke@435 605 NULL : jem.jni_env();
duke@435 606 jvmtiEventClassFileLoadHook callback = env->callbacks()->ClassFileLoadHook;
duke@435 607 if (callback != NULL) {
duke@435 608 (*callback)(env->jvmti_external(), jni_env,
duke@435 609 jem.class_being_redefined(),
duke@435 610 jem.jloader(), jem.class_name(),
duke@435 611 jem.protection_domain(),
duke@435 612 _curr_len, _curr_data,
duke@435 613 &new_len, &new_data);
duke@435 614 }
duke@435 615 if (new_data != NULL) {
duke@435 616 // this agent has modified class data.
duke@435 617 if (caching_needed && *_cached_data_ptr == NULL) {
duke@435 618 // data has been changed by the new retransformable agent
duke@435 619 // and it hasn't already been cached, cache it
zgu@3900 620 *_cached_data_ptr = (unsigned char *)os::malloc(_curr_len, mtInternal);
duke@435 621 memcpy(*_cached_data_ptr, _curr_data, _curr_len);
duke@435 622 *_cached_length_ptr = _curr_len;
duke@435 623 }
duke@435 624
duke@435 625 if (_curr_data != *_data_ptr) {
duke@435 626 // curr_data is previous agent modified class data.
duke@435 627 // And this has been changed by the new agent so
duke@435 628 // we can delete it now.
duke@435 629 _curr_env->Deallocate(_curr_data);
duke@435 630 }
duke@435 631
duke@435 632 // Class file data has changed by the current agent.
duke@435 633 _curr_data = new_data;
duke@435 634 _curr_len = new_len;
duke@435 635 // Save the current agent env we need this to deallocate the
duke@435 636 // memory allocated by this agent.
duke@435 637 _curr_env = env;
duke@435 638 }
duke@435 639 }
duke@435 640
duke@435 641 void copy_modified_data() {
duke@435 642 // if one of the agent has modified class file data.
duke@435 643 // Copy modified class data to new resources array.
duke@435 644 if (_curr_data != *_data_ptr) {
duke@435 645 *_data_ptr = NEW_RESOURCE_ARRAY(u1, _curr_len);
duke@435 646 memcpy(*_data_ptr, _curr_data, _curr_len);
duke@435 647 *_end_ptr = *_data_ptr + _curr_len;
duke@435 648 _curr_env->Deallocate(_curr_data);
duke@435 649 }
duke@435 650 }
duke@435 651 };
duke@435 652
duke@435 653 bool JvmtiExport::_should_post_class_file_load_hook = false;
duke@435 654
duke@435 655 // this entry is for class file load hook on class load, redefine and retransform
coleenp@2497 656 void JvmtiExport::post_class_file_load_hook(Symbol* h_name,
duke@435 657 Handle class_loader,
duke@435 658 Handle h_protection_domain,
duke@435 659 unsigned char **data_ptr,
duke@435 660 unsigned char **end_ptr,
duke@435 661 unsigned char **cached_data_ptr,
duke@435 662 jint *cached_length_ptr) {
duke@435 663 JvmtiClassFileLoadHookPoster poster(h_name, class_loader,
duke@435 664 h_protection_domain,
duke@435 665 data_ptr, end_ptr,
duke@435 666 cached_data_ptr,
duke@435 667 cached_length_ptr);
duke@435 668 poster.post();
duke@435 669 }
duke@435 670
duke@435 671 void JvmtiExport::report_unsupported(bool on) {
duke@435 672 // If any JVMTI service is turned on, we need to exit before native code
duke@435 673 // tries to access nonexistant services.
duke@435 674 if (on) {
duke@435 675 vm_exit_during_initialization("Java Kernel does not support JVMTI.");
duke@435 676 }
duke@435 677 }
duke@435 678
duke@435 679
coleenp@4037 680 static inline Klass* oop_to_klass(oop obj) {
coleenp@4037 681 Klass* k = obj->klass();
duke@435 682
duke@435 683 // if the object is a java.lang.Class then return the java mirror
never@1577 684 if (k == SystemDictionary::Class_klass()) {
duke@435 685 if (!java_lang_Class::is_primitive(obj)) {
coleenp@4037 686 k = java_lang_Class::as_Klass(obj);
duke@435 687 assert(k != NULL, "class for non-primitive mirror must exist");
duke@435 688 }
duke@435 689 }
duke@435 690 return k;
duke@435 691 }
duke@435 692
duke@435 693 class JvmtiVMObjectAllocEventMark : public JvmtiClassEventMark {
duke@435 694 private:
duke@435 695 jobject _jobj;
duke@435 696 jlong _size;
duke@435 697 public:
coleenp@4037 698 JvmtiVMObjectAllocEventMark(JavaThread *thread, oop obj) : JvmtiClassEventMark(thread, oop_to_klass(obj)) {
duke@435 699 _jobj = (jobject)to_jobject(obj);
duke@435 700 _size = obj->size() * wordSize;
duke@435 701 };
duke@435 702 jobject jni_jobject() { return _jobj; }
duke@435 703 jlong size() { return _size; }
duke@435 704 };
duke@435 705
duke@435 706 class JvmtiCompiledMethodLoadEventMark : public JvmtiMethodEventMark {
duke@435 707 private:
duke@435 708 jint _code_size;
duke@435 709 const void *_code_data;
duke@435 710 jint _map_length;
duke@435 711 jvmtiAddrLocationMap *_map;
duke@435 712 const void *_compile_info;
duke@435 713 public:
dcubed@1619 714 JvmtiCompiledMethodLoadEventMark(JavaThread *thread, nmethod *nm, void* compile_info_ptr = NULL)
duke@435 715 : JvmtiMethodEventMark(thread,methodHandle(thread, nm->method())) {
twisti@2103 716 _code_data = nm->insts_begin();
twisti@2103 717 _code_size = nm->insts_size();
dcubed@1619 718 _compile_info = compile_info_ptr; // Set void pointer of compiledMethodLoad Event. Default value is NULL.
duke@435 719 JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &_map, &_map_length);
duke@435 720 }
duke@435 721 ~JvmtiCompiledMethodLoadEventMark() {
zgu@3900 722 FREE_C_HEAP_ARRAY(jvmtiAddrLocationMap, _map, mtInternal);
duke@435 723 }
duke@435 724
duke@435 725 jint code_size() { return _code_size; }
duke@435 726 const void *code_data() { return _code_data; }
duke@435 727 jint map_length() { return _map_length; }
duke@435 728 const jvmtiAddrLocationMap* map() { return _map; }
duke@435 729 const void *compile_info() { return _compile_info; }
duke@435 730 };
duke@435 731
duke@435 732
duke@435 733
duke@435 734 class JvmtiMonitorEventMark : public JvmtiThreadEventMark {
duke@435 735 private:
duke@435 736 jobject _jobj;
duke@435 737 public:
duke@435 738 JvmtiMonitorEventMark(JavaThread *thread, oop object)
duke@435 739 : JvmtiThreadEventMark(thread){
duke@435 740 _jobj = to_jobject(object);
duke@435 741 }
duke@435 742 jobject jni_object() { return _jobj; }
duke@435 743 };
duke@435 744
duke@435 745 ///////////////////////////////////////////////////////////////
duke@435 746 //
duke@435 747 // pending CompiledMethodUnload support
duke@435 748 //
duke@435 749
kamg@2511 750 void JvmtiExport::post_compiled_method_unload(
kamg@2511 751 jmethodID method, const void *code_begin) {
kamg@2511 752 JavaThread* thread = JavaThread::current();
never@1932 753 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
never@1932 754 ("JVMTI [%s] method compile unload event triggered",
kamg@2511 755 JvmtiTrace::safe_get_thread_name(thread)));
never@1932 756
never@1932 757 // post the event for each environment that has this event enabled.
never@1932 758 JvmtiEnvIterator it;
never@1932 759 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
never@1932 760 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_UNLOAD)) {
never@1932 761
never@1932 762 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
never@1932 763 ("JVMTI [%s] class compile method unload event sent jmethodID " PTR_FORMAT,
kamg@2511 764 JvmtiTrace::safe_get_thread_name(thread), method));
never@1932 765
kamg@2511 766 ResourceMark rm(thread);
never@1932 767
kamg@2511 768 JvmtiEventMark jem(thread);
kamg@2511 769 JvmtiJavaThreadEventTransition jet(thread);
never@1932 770 jvmtiEventCompiledMethodUnload callback = env->callbacks()->CompiledMethodUnload;
never@1932 771 if (callback != NULL) {
never@1932 772 (*callback)(env->jvmti_external(), method, code_begin);
never@1932 773 }
never@1932 774 }
never@1932 775 }
never@1932 776 }
never@1932 777
duke@435 778 ///////////////////////////////////////////////////////////////
duke@435 779 //
duke@435 780 // JvmtiExport
duke@435 781 //
duke@435 782
coleenp@4037 783 void JvmtiExport::post_raw_breakpoint(JavaThread *thread, Method* method, address location) {
duke@435 784 HandleMark hm(thread);
duke@435 785 methodHandle mh(thread, method);
duke@435 786
duke@435 787 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 788 if (state == NULL) {
duke@435 789 return;
duke@435 790 }
duke@435 791 EVT_TRIG_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Trg Breakpoint triggered",
duke@435 792 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 793 JvmtiEnvThreadStateIterator it(state);
duke@435 794 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 795 ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_BREAKPOINT);
duke@435 796 if (!ets->breakpoint_posted() && ets->is_enabled(JVMTI_EVENT_BREAKPOINT)) {
duke@435 797 ThreadState old_os_state = thread->osthread()->get_state();
duke@435 798 thread->osthread()->set_state(BREAKPOINTED);
duke@435 799 EVT_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Evt Breakpoint sent %s.%s @ %d",
duke@435 800 JvmtiTrace::safe_get_thread_name(thread),
duke@435 801 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 802 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 803 location - mh()->code_base() ));
duke@435 804
duke@435 805 JvmtiEnv *env = ets->get_env();
duke@435 806 JvmtiLocationEventMark jem(thread, mh, location);
duke@435 807 JvmtiJavaThreadEventTransition jet(thread);
duke@435 808 jvmtiEventBreakpoint callback = env->callbacks()->Breakpoint;
duke@435 809 if (callback != NULL) {
duke@435 810 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 811 jem.jni_methodID(), jem.location());
duke@435 812 }
duke@435 813
duke@435 814 ets->set_breakpoint_posted();
duke@435 815 thread->osthread()->set_state(old_os_state);
duke@435 816 }
duke@435 817 }
duke@435 818 }
duke@435 819
duke@435 820 //////////////////////////////////////////////////////////////////////////////
duke@435 821
duke@435 822 bool JvmtiExport::_can_get_source_debug_extension = false;
duke@435 823 bool JvmtiExport::_can_maintain_original_method_order = false;
duke@435 824 bool JvmtiExport::_can_post_interpreter_events = false;
dcubed@1648 825 bool JvmtiExport::_can_post_on_exceptions = false;
duke@435 826 bool JvmtiExport::_can_post_breakpoint = false;
duke@435 827 bool JvmtiExport::_can_post_field_access = false;
duke@435 828 bool JvmtiExport::_can_post_field_modification = false;
duke@435 829 bool JvmtiExport::_can_post_method_entry = false;
duke@435 830 bool JvmtiExport::_can_post_method_exit = false;
duke@435 831 bool JvmtiExport::_can_pop_frame = false;
duke@435 832 bool JvmtiExport::_can_force_early_return = false;
duke@435 833
duke@435 834 bool JvmtiExport::_should_post_single_step = false;
duke@435 835 bool JvmtiExport::_should_post_field_access = false;
duke@435 836 bool JvmtiExport::_should_post_field_modification = false;
duke@435 837 bool JvmtiExport::_should_post_class_load = false;
duke@435 838 bool JvmtiExport::_should_post_class_prepare = false;
duke@435 839 bool JvmtiExport::_should_post_class_unload = false;
duke@435 840 bool JvmtiExport::_should_post_thread_life = false;
duke@435 841 bool JvmtiExport::_should_clean_up_heap_objects = false;
duke@435 842 bool JvmtiExport::_should_post_native_method_bind = false;
duke@435 843 bool JvmtiExport::_should_post_dynamic_code_generated = false;
duke@435 844 bool JvmtiExport::_should_post_data_dump = false;
duke@435 845 bool JvmtiExport::_should_post_compiled_method_load = false;
duke@435 846 bool JvmtiExport::_should_post_compiled_method_unload = false;
duke@435 847 bool JvmtiExport::_should_post_monitor_contended_enter = false;
duke@435 848 bool JvmtiExport::_should_post_monitor_contended_entered = false;
duke@435 849 bool JvmtiExport::_should_post_monitor_wait = false;
duke@435 850 bool JvmtiExport::_should_post_monitor_waited = false;
duke@435 851 bool JvmtiExport::_should_post_garbage_collection_start = false;
duke@435 852 bool JvmtiExport::_should_post_garbage_collection_finish = false;
duke@435 853 bool JvmtiExport::_should_post_object_free = false;
duke@435 854 bool JvmtiExport::_should_post_resource_exhausted = false;
duke@435 855 bool JvmtiExport::_should_post_vm_object_alloc = false;
dcubed@1648 856 bool JvmtiExport::_should_post_on_exceptions = false;
duke@435 857
duke@435 858 ////////////////////////////////////////////////////////////////////////////////////////////////
duke@435 859
duke@435 860
duke@435 861 //
duke@435 862 // JVMTI single step management
duke@435 863 //
coleenp@4037 864 void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, address location) {
duke@435 865 assert(JvmtiExport::should_post_single_step(), "must be single stepping");
duke@435 866
duke@435 867 HandleMark hm(thread);
duke@435 868 methodHandle mh(thread, method);
duke@435 869
duke@435 870 // update information about current location and post a step event
duke@435 871 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 872 if (state == NULL) {
duke@435 873 return;
duke@435 874 }
duke@435 875 EVT_TRIG_TRACE(JVMTI_EVENT_SINGLE_STEP, ("JVMTI [%s] Trg Single Step triggered",
duke@435 876 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 877 if (!state->hide_single_stepping()) {
duke@435 878 if (state->is_pending_step_for_popframe()) {
duke@435 879 state->process_pending_step_for_popframe();
duke@435 880 }
duke@435 881 if (state->is_pending_step_for_earlyret()) {
duke@435 882 state->process_pending_step_for_earlyret();
duke@435 883 }
duke@435 884 JvmtiExport::post_single_step(thread, mh(), location);
duke@435 885 }
duke@435 886 }
duke@435 887
duke@435 888
duke@435 889 void JvmtiExport::expose_single_stepping(JavaThread *thread) {
duke@435 890 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 891 if (state != NULL) {
duke@435 892 state->clear_hide_single_stepping();
duke@435 893 }
duke@435 894 }
duke@435 895
duke@435 896
duke@435 897 bool JvmtiExport::hide_single_stepping(JavaThread *thread) {
duke@435 898 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 899 if (state != NULL && state->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
duke@435 900 state->set_hide_single_stepping();
duke@435 901 return true;
duke@435 902 } else {
duke@435 903 return false;
duke@435 904 }
duke@435 905 }
duke@435 906
coleenp@4037 907 void JvmtiExport::post_class_load(JavaThread *thread, Klass* klass) {
duke@435 908 HandleMark hm(thread);
duke@435 909 KlassHandle kh(thread, klass);
duke@435 910
duke@435 911 EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_LOAD, ("JVMTI [%s] Trg Class Load triggered",
duke@435 912 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 913 JvmtiThreadState* state = thread->jvmti_thread_state();
duke@435 914 if (state == NULL) {
duke@435 915 return;
duke@435 916 }
duke@435 917 JvmtiEnvThreadStateIterator it(state);
duke@435 918 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 919 if (ets->is_enabled(JVMTI_EVENT_CLASS_LOAD)) {
duke@435 920 EVT_TRACE(JVMTI_EVENT_CLASS_LOAD, ("JVMTI [%s] Evt Class Load sent %s",
duke@435 921 JvmtiTrace::safe_get_thread_name(thread),
hseigel@4278 922 kh()==NULL? "NULL" : kh()->external_name() ));
duke@435 923
duke@435 924 JvmtiEnv *env = ets->get_env();
duke@435 925 JvmtiClassEventMark jem(thread, kh());
duke@435 926 JvmtiJavaThreadEventTransition jet(thread);
duke@435 927 jvmtiEventClassLoad callback = env->callbacks()->ClassLoad;
duke@435 928 if (callback != NULL) {
duke@435 929 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class());
duke@435 930 }
duke@435 931 }
duke@435 932 }
duke@435 933 }
duke@435 934
duke@435 935
coleenp@4037 936 void JvmtiExport::post_class_prepare(JavaThread *thread, Klass* klass) {
duke@435 937 HandleMark hm(thread);
duke@435 938 KlassHandle kh(thread, klass);
duke@435 939
duke@435 940 EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("JVMTI [%s] Trg Class Prepare triggered",
duke@435 941 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 942 JvmtiThreadState* state = thread->jvmti_thread_state();
duke@435 943 if (state == NULL) {
duke@435 944 return;
duke@435 945 }
duke@435 946 JvmtiEnvThreadStateIterator it(state);
duke@435 947 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 948 if (ets->is_enabled(JVMTI_EVENT_CLASS_PREPARE)) {
duke@435 949 EVT_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("JVMTI [%s] Evt Class Prepare sent %s",
duke@435 950 JvmtiTrace::safe_get_thread_name(thread),
hseigel@4278 951 kh()==NULL? "NULL" : kh()->external_name() ));
duke@435 952
duke@435 953 JvmtiEnv *env = ets->get_env();
duke@435 954 JvmtiClassEventMark jem(thread, kh());
duke@435 955 JvmtiJavaThreadEventTransition jet(thread);
duke@435 956 jvmtiEventClassPrepare callback = env->callbacks()->ClassPrepare;
duke@435 957 if (callback != NULL) {
duke@435 958 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class());
duke@435 959 }
duke@435 960 }
duke@435 961 }
duke@435 962 }
duke@435 963
coleenp@4037 964 void JvmtiExport::post_class_unload(Klass* klass) {
duke@435 965 Thread *thread = Thread::current();
duke@435 966 HandleMark hm(thread);
duke@435 967 KlassHandle kh(thread, klass);
duke@435 968
duke@435 969 EVT_TRIG_TRACE(EXT_EVENT_CLASS_UNLOAD, ("JVMTI [?] Trg Class Unload triggered" ));
duke@435 970 if (JvmtiEventController::is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) {
duke@435 971 assert(thread->is_VM_thread(), "wrong thread");
duke@435 972
duke@435 973 // get JavaThread for whom we are proxy
duke@435 974 JavaThread *real_thread =
duke@435 975 (JavaThread *)((VMThread *)thread)->vm_operation()->calling_thread();
duke@435 976
duke@435 977 JvmtiEnvIterator it;
duke@435 978 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 979 if (env->is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) {
duke@435 980 EVT_TRACE(EXT_EVENT_CLASS_UNLOAD, ("JVMTI [?] Evt Class Unload sent %s",
hseigel@4278 981 kh()==NULL? "NULL" : kh()->external_name() ));
duke@435 982
duke@435 983 // do everything manually, since this is a proxy - needs special care
duke@435 984 JNIEnv* jni_env = real_thread->jni_environment();
duke@435 985 jthread jt = (jthread)JNIHandles::make_local(real_thread, real_thread->threadObj());
hseigel@4278 986 jclass jk = (jclass)JNIHandles::make_local(real_thread, kh()->java_mirror());
duke@435 987
duke@435 988 // Before we call the JVMTI agent, we have to set the state in the
duke@435 989 // thread for which we are proxying.
duke@435 990 JavaThreadState prev_state = real_thread->thread_state();
duke@435 991 assert(prev_state == _thread_blocked, "JavaThread should be at safepoint");
duke@435 992 real_thread->set_thread_state(_thread_in_native);
duke@435 993
duke@435 994 jvmtiExtensionEvent callback = env->ext_callbacks()->ClassUnload;
duke@435 995 if (callback != NULL) {
duke@435 996 (*callback)(env->jvmti_external(), jni_env, jt, jk);
duke@435 997 }
duke@435 998
duke@435 999 assert(real_thread->thread_state() == _thread_in_native,
duke@435 1000 "JavaThread should be in native");
duke@435 1001 real_thread->set_thread_state(prev_state);
duke@435 1002
duke@435 1003 JNIHandles::destroy_local(jk);
duke@435 1004 JNIHandles::destroy_local(jt);
duke@435 1005 }
duke@435 1006 }
duke@435 1007 }
duke@435 1008 }
duke@435 1009
duke@435 1010
duke@435 1011 void JvmtiExport::post_thread_start(JavaThread *thread) {
duke@435 1012 assert(thread->thread_state() == _thread_in_vm, "must be in vm state");
duke@435 1013
duke@435 1014 EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_START, ("JVMTI [%s] Trg Thread Start event triggered",
duke@435 1015 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1016
duke@435 1017 // do JVMTI thread initialization (if needed)
duke@435 1018 JvmtiEventController::thread_started(thread);
duke@435 1019
duke@435 1020 // Do not post thread start event for hidden java thread.
duke@435 1021 if (JvmtiEventController::is_enabled(JVMTI_EVENT_THREAD_START) &&
duke@435 1022 !thread->is_hidden_from_external_view()) {
duke@435 1023 JvmtiEnvIterator it;
duke@435 1024 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1025 if (env->is_enabled(JVMTI_EVENT_THREAD_START)) {
duke@435 1026 EVT_TRACE(JVMTI_EVENT_THREAD_START, ("JVMTI [%s] Evt Thread Start event sent",
duke@435 1027 JvmtiTrace::safe_get_thread_name(thread) ));
duke@435 1028
duke@435 1029 JvmtiThreadEventMark jem(thread);
duke@435 1030 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1031 jvmtiEventThreadStart callback = env->callbacks()->ThreadStart;
duke@435 1032 if (callback != NULL) {
duke@435 1033 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
duke@435 1034 }
duke@435 1035 }
duke@435 1036 }
duke@435 1037 }
duke@435 1038 }
duke@435 1039
duke@435 1040
duke@435 1041 void JvmtiExport::post_thread_end(JavaThread *thread) {
duke@435 1042 EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_END, ("JVMTI [%s] Trg Thread End event triggered",
duke@435 1043 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1044
duke@435 1045 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1046 if (state == NULL) {
duke@435 1047 return;
duke@435 1048 }
duke@435 1049
duke@435 1050 // Do not post thread end event for hidden java thread.
duke@435 1051 if (state->is_enabled(JVMTI_EVENT_THREAD_END) &&
duke@435 1052 !thread->is_hidden_from_external_view()) {
duke@435 1053
duke@435 1054 JvmtiEnvThreadStateIterator it(state);
duke@435 1055 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1056 if (ets->is_enabled(JVMTI_EVENT_THREAD_END)) {
duke@435 1057 EVT_TRACE(JVMTI_EVENT_THREAD_END, ("JVMTI [%s] Evt Thread End event sent",
duke@435 1058 JvmtiTrace::safe_get_thread_name(thread) ));
duke@435 1059
duke@435 1060 JvmtiEnv *env = ets->get_env();
duke@435 1061 JvmtiThreadEventMark jem(thread);
duke@435 1062 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1063 jvmtiEventThreadEnd callback = env->callbacks()->ThreadEnd;
duke@435 1064 if (callback != NULL) {
duke@435 1065 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
duke@435 1066 }
duke@435 1067 }
duke@435 1068 }
duke@435 1069 }
duke@435 1070 }
duke@435 1071
duke@435 1072 void JvmtiExport::post_object_free(JvmtiEnv* env, jlong tag) {
duke@435 1073 assert(SafepointSynchronize::is_at_safepoint(), "must be executed at safepoint");
duke@435 1074 assert(env->is_enabled(JVMTI_EVENT_OBJECT_FREE), "checking");
duke@435 1075
duke@435 1076 EVT_TRIG_TRACE(JVMTI_EVENT_OBJECT_FREE, ("JVMTI [?] Trg Object Free triggered" ));
duke@435 1077 EVT_TRACE(JVMTI_EVENT_OBJECT_FREE, ("JVMTI [?] Evt Object Free sent"));
duke@435 1078
duke@435 1079 jvmtiEventObjectFree callback = env->callbacks()->ObjectFree;
duke@435 1080 if (callback != NULL) {
duke@435 1081 (*callback)(env->jvmti_external(), tag);
duke@435 1082 }
duke@435 1083 }
duke@435 1084
duke@435 1085 void JvmtiExport::post_resource_exhausted(jint resource_exhausted_flags, const char* description) {
duke@435 1086 EVT_TRIG_TRACE(JVMTI_EVENT_RESOURCE_EXHAUSTED, ("JVMTI Trg resource exhausted event triggered" ));
duke@435 1087
duke@435 1088 JvmtiEnvIterator it;
duke@435 1089 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1090 if (env->is_enabled(JVMTI_EVENT_RESOURCE_EXHAUSTED)) {
duke@435 1091 EVT_TRACE(JVMTI_EVENT_RESOURCE_EXHAUSTED, ("JVMTI Evt resource exhausted event sent" ));
duke@435 1092
duke@435 1093 JavaThread *thread = JavaThread::current();
duke@435 1094 JvmtiThreadEventMark jem(thread);
duke@435 1095 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1096 jvmtiEventResourceExhausted callback = env->callbacks()->ResourceExhausted;
duke@435 1097 if (callback != NULL) {
duke@435 1098 (*callback)(env->jvmti_external(), jem.jni_env(),
duke@435 1099 resource_exhausted_flags, NULL, description);
duke@435 1100 }
duke@435 1101 }
duke@435 1102 }
duke@435 1103 }
duke@435 1104
coleenp@4037 1105 void JvmtiExport::post_method_entry(JavaThread *thread, Method* method, frame current_frame) {
duke@435 1106 HandleMark hm(thread);
duke@435 1107 methodHandle mh(thread, method);
duke@435 1108
duke@435 1109 EVT_TRIG_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("JVMTI [%s] Trg Method Entry triggered %s.%s",
duke@435 1110 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1111 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1112 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1113
duke@435 1114 JvmtiThreadState* state = thread->jvmti_thread_state();
duke@435 1115 if (state == NULL || !state->is_interp_only_mode()) {
duke@435 1116 // for any thread that actually wants method entry, interp_only_mode is set
duke@435 1117 return;
duke@435 1118 }
duke@435 1119
duke@435 1120 state->incr_cur_stack_depth();
duke@435 1121
duke@435 1122 if (state->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) {
duke@435 1123 JvmtiEnvThreadStateIterator it(state);
duke@435 1124 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1125 if (ets->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) {
duke@435 1126 EVT_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("JVMTI [%s] Evt Method Entry sent %s.%s",
duke@435 1127 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1128 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1129 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1130
duke@435 1131 JvmtiEnv *env = ets->get_env();
duke@435 1132 JvmtiMethodEventMark jem(thread, mh);
duke@435 1133 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1134 jvmtiEventMethodEntry callback = env->callbacks()->MethodEntry;
duke@435 1135 if (callback != NULL) {
duke@435 1136 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_methodID());
duke@435 1137 }
duke@435 1138 }
duke@435 1139 }
duke@435 1140 }
duke@435 1141 }
duke@435 1142
coleenp@4037 1143 void JvmtiExport::post_method_exit(JavaThread *thread, Method* method, frame current_frame) {
duke@435 1144 HandleMark hm(thread);
duke@435 1145 methodHandle mh(thread, method);
duke@435 1146
duke@435 1147 EVT_TRIG_TRACE(JVMTI_EVENT_METHOD_EXIT, ("JVMTI [%s] Trg Method Exit triggered %s.%s",
duke@435 1148 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1149 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1150 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1151
duke@435 1152 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1153 if (state == NULL || !state->is_interp_only_mode()) {
duke@435 1154 // for any thread that actually wants method exit, interp_only_mode is set
duke@435 1155 return;
duke@435 1156 }
duke@435 1157
duke@435 1158 // return a flag when a method terminates by throwing an exception
duke@435 1159 // i.e. if an exception is thrown and it's not caught by the current method
duke@435 1160 bool exception_exit = state->is_exception_detected() && !state->is_exception_caught();
duke@435 1161
duke@435 1162
duke@435 1163 if (state->is_enabled(JVMTI_EVENT_METHOD_EXIT)) {
duke@435 1164 Handle result;
duke@435 1165 jvalue value;
duke@435 1166 value.j = 0L;
duke@435 1167
duke@435 1168 // if the method hasn't been popped because of an exception then we populate
duke@435 1169 // the return_value parameter for the callback. At this point we only have
duke@435 1170 // the address of a "raw result" and we just call into the interpreter to
duke@435 1171 // convert this into a jvalue.
duke@435 1172 if (!exception_exit) {
duke@435 1173 oop oop_result;
duke@435 1174 BasicType type = current_frame.interpreter_frame_result(&oop_result, &value);
duke@435 1175 if (type == T_OBJECT || type == T_ARRAY) {
duke@435 1176 result = Handle(thread, oop_result);
duke@435 1177 }
duke@435 1178 }
duke@435 1179
duke@435 1180 JvmtiEnvThreadStateIterator it(state);
duke@435 1181 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1182 if (ets->is_enabled(JVMTI_EVENT_METHOD_EXIT)) {
duke@435 1183 EVT_TRACE(JVMTI_EVENT_METHOD_EXIT, ("JVMTI [%s] Evt Method Exit sent %s.%s",
duke@435 1184 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1185 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1186 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1187
duke@435 1188 JvmtiEnv *env = ets->get_env();
duke@435 1189 JvmtiMethodEventMark jem(thread, mh);
duke@435 1190 if (result.not_null()) {
duke@435 1191 value.l = JNIHandles::make_local(thread, result());
duke@435 1192 }
duke@435 1193 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1194 jvmtiEventMethodExit callback = env->callbacks()->MethodExit;
duke@435 1195 if (callback != NULL) {
duke@435 1196 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1197 jem.jni_methodID(), exception_exit, value);
duke@435 1198 }
duke@435 1199 }
duke@435 1200 }
duke@435 1201 }
duke@435 1202
duke@435 1203 if (state->is_enabled(JVMTI_EVENT_FRAME_POP)) {
duke@435 1204 JvmtiEnvThreadStateIterator it(state);
duke@435 1205 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1206 int cur_frame_number = state->cur_stack_depth();
duke@435 1207
duke@435 1208 if (ets->is_frame_pop(cur_frame_number)) {
duke@435 1209 // we have a NotifyFramePop entry for this frame.
duke@435 1210 // now check that this env/thread wants this event
duke@435 1211 if (ets->is_enabled(JVMTI_EVENT_FRAME_POP)) {
duke@435 1212 EVT_TRACE(JVMTI_EVENT_FRAME_POP, ("JVMTI [%s] Evt Frame Pop sent %s.%s",
duke@435 1213 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1214 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1215 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1216
duke@435 1217 // we also need to issue a frame pop event for this frame
duke@435 1218 JvmtiEnv *env = ets->get_env();
duke@435 1219 JvmtiMethodEventMark jem(thread, mh);
duke@435 1220 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1221 jvmtiEventFramePop callback = env->callbacks()->FramePop;
duke@435 1222 if (callback != NULL) {
duke@435 1223 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1224 jem.jni_methodID(), exception_exit);
duke@435 1225 }
duke@435 1226 }
duke@435 1227 // remove the frame's entry
duke@435 1228 ets->clear_frame_pop(cur_frame_number);
duke@435 1229 }
duke@435 1230 }
duke@435 1231 }
duke@435 1232
duke@435 1233 state->decr_cur_stack_depth();
duke@435 1234 }
duke@435 1235
duke@435 1236
duke@435 1237 // Todo: inline this for optimization
coleenp@4037 1238 void JvmtiExport::post_single_step(JavaThread *thread, Method* method, address location) {
duke@435 1239 HandleMark hm(thread);
duke@435 1240 methodHandle mh(thread, method);
duke@435 1241
duke@435 1242 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1243 if (state == NULL) {
duke@435 1244 return;
duke@435 1245 }
duke@435 1246 JvmtiEnvThreadStateIterator it(state);
duke@435 1247 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1248 ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_SINGLE_STEP);
duke@435 1249 if (!ets->single_stepping_posted() && ets->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
duke@435 1250 EVT_TRACE(JVMTI_EVENT_SINGLE_STEP, ("JVMTI [%s] Evt Single Step sent %s.%s @ %d",
duke@435 1251 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1252 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1253 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1254 location - mh()->code_base() ));
duke@435 1255
duke@435 1256 JvmtiEnv *env = ets->get_env();
duke@435 1257 JvmtiLocationEventMark jem(thread, mh, location);
duke@435 1258 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1259 jvmtiEventSingleStep callback = env->callbacks()->SingleStep;
duke@435 1260 if (callback != NULL) {
duke@435 1261 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1262 jem.jni_methodID(), jem.location());
duke@435 1263 }
duke@435 1264
duke@435 1265 ets->set_single_stepping_posted();
duke@435 1266 }
duke@435 1267 }
duke@435 1268 }
duke@435 1269
duke@435 1270
coleenp@4037 1271 void JvmtiExport::post_exception_throw(JavaThread *thread, Method* method, address location, oop exception) {
duke@435 1272 HandleMark hm(thread);
duke@435 1273 methodHandle mh(thread, method);
duke@435 1274 Handle exception_handle(thread, exception);
duke@435 1275
duke@435 1276 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1277 if (state == NULL) {
duke@435 1278 return;
duke@435 1279 }
duke@435 1280
duke@435 1281 EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION, ("JVMTI [%s] Trg Exception thrown triggered",
duke@435 1282 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1283 if (!state->is_exception_detected()) {
duke@435 1284 state->set_exception_detected();
duke@435 1285 JvmtiEnvThreadStateIterator it(state);
duke@435 1286 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1287 if (ets->is_enabled(JVMTI_EVENT_EXCEPTION) && (exception != NULL)) {
duke@435 1288
duke@435 1289 EVT_TRACE(JVMTI_EVENT_EXCEPTION,
duke@435 1290 ("JVMTI [%s] Evt Exception thrown sent %s.%s @ %d",
duke@435 1291 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1292 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1293 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1294 location - mh()->code_base() ));
duke@435 1295
duke@435 1296 JvmtiEnv *env = ets->get_env();
duke@435 1297 JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
duke@435 1298
duke@435 1299 // It's okay to clear these exceptions here because we duplicate
duke@435 1300 // this lookup in InterpreterRuntime::exception_handler_for_exception.
duke@435 1301 EXCEPTION_MARK;
duke@435 1302
duke@435 1303 bool should_repeat;
duke@435 1304 vframeStream st(thread);
duke@435 1305 assert(!st.at_end(), "cannot be at end");
coleenp@4037 1306 Method* current_method = NULL;
jiangli@4405 1307 // A GC may occur during the Method::fast_exception_handler_bci_for()
jiangli@4405 1308 // call below if it needs to load the constraint class. Using a
jiangli@4405 1309 // methodHandle to keep the 'current_method' from being deallocated
jiangli@4405 1310 // if GC happens.
jiangli@4405 1311 methodHandle current_mh = methodHandle(thread, current_method);
duke@435 1312 int current_bci = -1;
duke@435 1313 do {
duke@435 1314 current_method = st.method();
jiangli@4405 1315 current_mh = methodHandle(thread, current_method);
duke@435 1316 current_bci = st.bci();
duke@435 1317 do {
duke@435 1318 should_repeat = false;
duke@435 1319 KlassHandle eh_klass(thread, exception_handle()->klass());
jiangli@4405 1320 current_bci = Method::fast_exception_handler_bci_for(
jiangli@4405 1321 current_mh, eh_klass, current_bci, THREAD);
duke@435 1322 if (HAS_PENDING_EXCEPTION) {
coleenp@4037 1323 exception_handle = Handle(thread, PENDING_EXCEPTION);
duke@435 1324 CLEAR_PENDING_EXCEPTION;
duke@435 1325 should_repeat = true;
duke@435 1326 }
duke@435 1327 } while (should_repeat && (current_bci != -1));
duke@435 1328 st.next();
duke@435 1329 } while ((current_bci < 0) && (!st.at_end()));
duke@435 1330
duke@435 1331 jmethodID catch_jmethodID;
duke@435 1332 if (current_bci < 0) {
duke@435 1333 catch_jmethodID = 0;
duke@435 1334 current_bci = 0;
duke@435 1335 } else {
jiangli@4405 1336 catch_jmethodID = jem.to_jmethodID(current_mh);
duke@435 1337 }
duke@435 1338
duke@435 1339 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1340 jvmtiEventException callback = env->callbacks()->Exception;
duke@435 1341 if (callback != NULL) {
duke@435 1342 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1343 jem.jni_methodID(), jem.location(),
duke@435 1344 jem.exception(),
duke@435 1345 catch_jmethodID, current_bci);
duke@435 1346 }
duke@435 1347 }
duke@435 1348 }
duke@435 1349 }
duke@435 1350
duke@435 1351 // frames may get popped because of this throw, be safe - invalidate cached depth
duke@435 1352 state->invalidate_cur_stack_depth();
duke@435 1353 }
duke@435 1354
duke@435 1355
coleenp@4037 1356 void JvmtiExport::notice_unwind_due_to_exception(JavaThread *thread, Method* method, address location, oop exception, bool in_handler_frame) {
duke@435 1357 HandleMark hm(thread);
duke@435 1358 methodHandle mh(thread, method);
duke@435 1359 Handle exception_handle(thread, exception);
duke@435 1360
duke@435 1361 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1362 if (state == NULL) {
duke@435 1363 return;
duke@435 1364 }
duke@435 1365 EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION_CATCH,
duke@435 1366 ("JVMTI [%s] Trg unwind_due_to_exception triggered %s.%s @ %s%d - %s",
duke@435 1367 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1368 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1369 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1370 location==0? "no location:" : "",
duke@435 1371 location==0? 0 : location - mh()->code_base(),
duke@435 1372 in_handler_frame? "in handler frame" : "not handler frame" ));
duke@435 1373
duke@435 1374 if (state->is_exception_detected()) {
duke@435 1375
duke@435 1376 state->invalidate_cur_stack_depth();
duke@435 1377 if (!in_handler_frame) {
duke@435 1378 // Not in exception handler.
duke@435 1379 if(state->is_interp_only_mode()) {
duke@435 1380 // method exit and frame pop events are posted only in interp mode.
duke@435 1381 // When these events are enabled code should be in running in interp mode.
duke@435 1382 JvmtiExport::post_method_exit(thread, method, thread->last_frame());
duke@435 1383 // The cached cur_stack_depth might have changed from the
duke@435 1384 // operations of frame pop or method exit. We are not 100% sure
duke@435 1385 // the cached cur_stack_depth is still valid depth so invalidate
duke@435 1386 // it.
duke@435 1387 state->invalidate_cur_stack_depth();
duke@435 1388 }
duke@435 1389 } else {
duke@435 1390 // In exception handler frame. Report exception catch.
duke@435 1391 assert(location != NULL, "must be a known location");
duke@435 1392 // Update cur_stack_depth - the frames above the current frame
duke@435 1393 // have been unwound due to this exception:
duke@435 1394 assert(!state->is_exception_caught(), "exception must not be caught yet.");
duke@435 1395 state->set_exception_caught();
duke@435 1396
duke@435 1397 JvmtiEnvThreadStateIterator it(state);
duke@435 1398 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1399 if (ets->is_enabled(JVMTI_EVENT_EXCEPTION_CATCH) && (exception_handle() != NULL)) {
duke@435 1400 EVT_TRACE(JVMTI_EVENT_EXCEPTION_CATCH,
duke@435 1401 ("JVMTI [%s] Evt ExceptionCatch sent %s.%s @ %d",
duke@435 1402 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1403 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1404 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1405 location - mh()->code_base() ));
duke@435 1406
duke@435 1407 JvmtiEnv *env = ets->get_env();
duke@435 1408 JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
duke@435 1409 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1410 jvmtiEventExceptionCatch callback = env->callbacks()->ExceptionCatch;
duke@435 1411 if (callback != NULL) {
duke@435 1412 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1413 jem.jni_methodID(), jem.location(),
duke@435 1414 jem.exception());
duke@435 1415 }
duke@435 1416 }
duke@435 1417 }
duke@435 1418 }
duke@435 1419 }
duke@435 1420 }
duke@435 1421
duke@435 1422 oop JvmtiExport::jni_GetField_probe(JavaThread *thread, jobject jobj, oop obj,
coleenp@4037 1423 Klass* klass, jfieldID fieldID, bool is_static) {
duke@435 1424 if (*((int *)get_field_access_count_addr()) > 0 && thread->has_last_Java_frame()) {
duke@435 1425 // At least one field access watch is set so we have more work
duke@435 1426 // to do. This wrapper is used by entry points that allow us
duke@435 1427 // to create handles in post_field_access_by_jni().
duke@435 1428 post_field_access_by_jni(thread, obj, klass, fieldID, is_static);
duke@435 1429 // event posting can block so refetch oop if we were passed a jobj
duke@435 1430 if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
duke@435 1431 }
duke@435 1432 return obj;
duke@435 1433 }
duke@435 1434
duke@435 1435 oop JvmtiExport::jni_GetField_probe_nh(JavaThread *thread, jobject jobj, oop obj,
coleenp@4037 1436 Klass* klass, jfieldID fieldID, bool is_static) {
duke@435 1437 if (*((int *)get_field_access_count_addr()) > 0 && thread->has_last_Java_frame()) {
duke@435 1438 // At least one field access watch is set so we have more work
duke@435 1439 // to do. This wrapper is used by "quick" entry points that don't
duke@435 1440 // allow us to create handles in post_field_access_by_jni(). We
duke@435 1441 // override that with a ResetNoHandleMark.
duke@435 1442 ResetNoHandleMark rnhm;
duke@435 1443 post_field_access_by_jni(thread, obj, klass, fieldID, is_static);
duke@435 1444 // event posting can block so refetch oop if we were passed a jobj
duke@435 1445 if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
duke@435 1446 }
duke@435 1447 return obj;
duke@435 1448 }
duke@435 1449
duke@435 1450 void JvmtiExport::post_field_access_by_jni(JavaThread *thread, oop obj,
coleenp@4037 1451 Klass* klass, jfieldID fieldID, bool is_static) {
duke@435 1452 // We must be called with a Java context in order to provide reasonable
duke@435 1453 // values for the klazz, method, and location fields. The callers of this
duke@435 1454 // function don't make the call unless there is a Java context.
duke@435 1455 assert(thread->has_last_Java_frame(), "must be called with a Java context");
duke@435 1456
duke@435 1457 ResourceMark rm;
duke@435 1458 fieldDescriptor fd;
duke@435 1459 // if get_field_descriptor finds fieldID to be invalid, then we just bail
duke@435 1460 bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd);
duke@435 1461 assert(valid_fieldID == true,"post_field_access_by_jni called with invalid fieldID");
duke@435 1462 if (!valid_fieldID) return;
duke@435 1463 // field accesses are not watched so bail
duke@435 1464 if (!fd.is_field_access_watched()) return;
duke@435 1465
duke@435 1466 HandleMark hm(thread);
duke@435 1467 KlassHandle h_klass(thread, klass);
duke@435 1468 Handle h_obj;
duke@435 1469 if (!is_static) {
duke@435 1470 // non-static field accessors have an object, but we need a handle
duke@435 1471 assert(obj != NULL, "non-static needs an object");
duke@435 1472 h_obj = Handle(thread, obj);
duke@435 1473 }
duke@435 1474 post_field_access(thread,
duke@435 1475 thread->last_frame().interpreter_frame_method(),
duke@435 1476 thread->last_frame().interpreter_frame_bcp(),
duke@435 1477 h_klass, h_obj, fieldID);
duke@435 1478 }
duke@435 1479
coleenp@4037 1480 void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
duke@435 1481 address location, KlassHandle field_klass, Handle object, jfieldID field) {
duke@435 1482
duke@435 1483 HandleMark hm(thread);
duke@435 1484 methodHandle mh(thread, method);
duke@435 1485
duke@435 1486 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1487 if (state == NULL) {
duke@435 1488 return;
duke@435 1489 }
duke@435 1490 EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Trg Field Access event triggered",
duke@435 1491 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1492 JvmtiEnvThreadStateIterator it(state);
duke@435 1493 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1494 if (ets->is_enabled(JVMTI_EVENT_FIELD_ACCESS)) {
duke@435 1495 EVT_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Evt Field Access event sent %s.%s @ %d",
duke@435 1496 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1497 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1498 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1499 location - mh()->code_base() ));
duke@435 1500
duke@435 1501 JvmtiEnv *env = ets->get_env();
duke@435 1502 JvmtiLocationEventMark jem(thread, mh, location);
duke@435 1503 jclass field_jclass = jem.to_jclass(field_klass());
duke@435 1504 jobject field_jobject = jem.to_jobject(object());
duke@435 1505 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1506 jvmtiEventFieldAccess callback = env->callbacks()->FieldAccess;
duke@435 1507 if (callback != NULL) {
duke@435 1508 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1509 jem.jni_methodID(), jem.location(),
duke@435 1510 field_jclass, field_jobject, field);
duke@435 1511 }
duke@435 1512 }
duke@435 1513 }
duke@435 1514 }
duke@435 1515
duke@435 1516 oop JvmtiExport::jni_SetField_probe(JavaThread *thread, jobject jobj, oop obj,
coleenp@4037 1517 Klass* klass, jfieldID fieldID, bool is_static,
duke@435 1518 char sig_type, jvalue *value) {
duke@435 1519 if (*((int *)get_field_modification_count_addr()) > 0 && thread->has_last_Java_frame()) {
duke@435 1520 // At least one field modification watch is set so we have more work
duke@435 1521 // to do. This wrapper is used by entry points that allow us
duke@435 1522 // to create handles in post_field_modification_by_jni().
duke@435 1523 post_field_modification_by_jni(thread, obj, klass, fieldID, is_static, sig_type, value);
duke@435 1524 // event posting can block so refetch oop if we were passed a jobj
duke@435 1525 if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
duke@435 1526 }
duke@435 1527 return obj;
duke@435 1528 }
duke@435 1529
duke@435 1530 oop JvmtiExport::jni_SetField_probe_nh(JavaThread *thread, jobject jobj, oop obj,
coleenp@4037 1531 Klass* klass, jfieldID fieldID, bool is_static,
duke@435 1532 char sig_type, jvalue *value) {
duke@435 1533 if (*((int *)get_field_modification_count_addr()) > 0 && thread->has_last_Java_frame()) {
duke@435 1534 // At least one field modification watch is set so we have more work
duke@435 1535 // to do. This wrapper is used by "quick" entry points that don't
duke@435 1536 // allow us to create handles in post_field_modification_by_jni(). We
duke@435 1537 // override that with a ResetNoHandleMark.
duke@435 1538 ResetNoHandleMark rnhm;
duke@435 1539 post_field_modification_by_jni(thread, obj, klass, fieldID, is_static, sig_type, value);
duke@435 1540 // event posting can block so refetch oop if we were passed a jobj
duke@435 1541 if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
duke@435 1542 }
duke@435 1543 return obj;
duke@435 1544 }
duke@435 1545
duke@435 1546 void JvmtiExport::post_field_modification_by_jni(JavaThread *thread, oop obj,
coleenp@4037 1547 Klass* klass, jfieldID fieldID, bool is_static,
duke@435 1548 char sig_type, jvalue *value) {
duke@435 1549 // We must be called with a Java context in order to provide reasonable
duke@435 1550 // values for the klazz, method, and location fields. The callers of this
duke@435 1551 // function don't make the call unless there is a Java context.
duke@435 1552 assert(thread->has_last_Java_frame(), "must be called with Java context");
duke@435 1553
duke@435 1554 ResourceMark rm;
duke@435 1555 fieldDescriptor fd;
duke@435 1556 // if get_field_descriptor finds fieldID to be invalid, then we just bail
duke@435 1557 bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd);
duke@435 1558 assert(valid_fieldID == true,"post_field_modification_by_jni called with invalid fieldID");
duke@435 1559 if (!valid_fieldID) return;
duke@435 1560 // field modifications are not watched so bail
duke@435 1561 if (!fd.is_field_modification_watched()) return;
duke@435 1562
duke@435 1563 HandleMark hm(thread);
duke@435 1564
duke@435 1565 Handle h_obj;
duke@435 1566 if (!is_static) {
duke@435 1567 // non-static field accessors have an object, but we need a handle
duke@435 1568 assert(obj != NULL, "non-static needs an object");
duke@435 1569 h_obj = Handle(thread, obj);
duke@435 1570 }
duke@435 1571 KlassHandle h_klass(thread, klass);
duke@435 1572 post_field_modification(thread,
duke@435 1573 thread->last_frame().interpreter_frame_method(),
duke@435 1574 thread->last_frame().interpreter_frame_bcp(),
duke@435 1575 h_klass, h_obj, fieldID, sig_type, value);
duke@435 1576 }
duke@435 1577
coleenp@4037 1578 void JvmtiExport::post_raw_field_modification(JavaThread *thread, Method* method,
duke@435 1579 address location, KlassHandle field_klass, Handle object, jfieldID field,
duke@435 1580 char sig_type, jvalue *value) {
duke@435 1581
duke@435 1582 if (sig_type == 'I' || sig_type == 'Z' || sig_type == 'C' || sig_type == 'S') {
duke@435 1583 // 'I' instructions are used for byte, char, short and int.
duke@435 1584 // determine which it really is, and convert
duke@435 1585 fieldDescriptor fd;
duke@435 1586 bool found = JvmtiEnv::get_field_descriptor(field_klass(), field, &fd);
duke@435 1587 // should be found (if not, leave as is)
duke@435 1588 if (found) {
duke@435 1589 jint ival = value->i;
duke@435 1590 // convert value from int to appropriate type
duke@435 1591 switch (fd.field_type()) {
duke@435 1592 case T_BOOLEAN:
duke@435 1593 sig_type = 'Z';
duke@435 1594 value->i = 0; // clear it
duke@435 1595 value->z = (jboolean)ival;
duke@435 1596 break;
duke@435 1597 case T_BYTE:
duke@435 1598 sig_type = 'B';
duke@435 1599 value->i = 0; // clear it
duke@435 1600 value->b = (jbyte)ival;
duke@435 1601 break;
duke@435 1602 case T_CHAR:
duke@435 1603 sig_type = 'C';
duke@435 1604 value->i = 0; // clear it
duke@435 1605 value->c = (jchar)ival;
duke@435 1606 break;
duke@435 1607 case T_SHORT:
duke@435 1608 sig_type = 'S';
duke@435 1609 value->i = 0; // clear it
duke@435 1610 value->s = (jshort)ival;
duke@435 1611 break;
duke@435 1612 case T_INT:
duke@435 1613 // nothing to do
duke@435 1614 break;
duke@435 1615 default:
duke@435 1616 // this is an integer instruction, should be one of above
duke@435 1617 ShouldNotReachHere();
duke@435 1618 break;
duke@435 1619 }
duke@435 1620 }
duke@435 1621 }
duke@435 1622
duke@435 1623 // convert oop to JNI handle.
duke@435 1624 if (sig_type == 'L' || sig_type == '[') {
duke@435 1625 value->l = (jobject)JNIHandles::make_local(thread, (oop)value->l);
duke@435 1626 }
duke@435 1627
duke@435 1628 post_field_modification(thread, method, location, field_klass, object, field, sig_type, value);
duke@435 1629
duke@435 1630 // Destroy the JNI handle allocated above.
duke@435 1631 if (sig_type == 'L') {
duke@435 1632 JNIHandles::destroy_local(value->l);
duke@435 1633 }
duke@435 1634 }
duke@435 1635
coleenp@4037 1636 void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
duke@435 1637 address location, KlassHandle field_klass, Handle object, jfieldID field,
duke@435 1638 char sig_type, jvalue *value_ptr) {
duke@435 1639
duke@435 1640 HandleMark hm(thread);
duke@435 1641 methodHandle mh(thread, method);
duke@435 1642
duke@435 1643 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1644 if (state == NULL) {
duke@435 1645 return;
duke@435 1646 }
duke@435 1647 EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
duke@435 1648 ("JVMTI [%s] Trg Field Modification event triggered",
duke@435 1649 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1650
duke@435 1651 JvmtiEnvThreadStateIterator it(state);
duke@435 1652 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1653 if (ets->is_enabled(JVMTI_EVENT_FIELD_MODIFICATION)) {
duke@435 1654 EVT_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
duke@435 1655 ("JVMTI [%s] Evt Field Modification event sent %s.%s @ %d",
duke@435 1656 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1657 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1658 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1659 location - mh()->code_base() ));
duke@435 1660
duke@435 1661 JvmtiEnv *env = ets->get_env();
duke@435 1662 JvmtiLocationEventMark jem(thread, mh, location);
duke@435 1663 jclass field_jclass = jem.to_jclass(field_klass());
duke@435 1664 jobject field_jobject = jem.to_jobject(object());
duke@435 1665 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1666 jvmtiEventFieldModification callback = env->callbacks()->FieldModification;
duke@435 1667 if (callback != NULL) {
duke@435 1668 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1669 jem.jni_methodID(), jem.location(),
duke@435 1670 field_jclass, field_jobject, field, sig_type, *value_ptr);
duke@435 1671 }
duke@435 1672 }
duke@435 1673 }
duke@435 1674 }
duke@435 1675
coleenp@4037 1676 void JvmtiExport::post_native_method_bind(Method* method, address* function_ptr) {
duke@435 1677 JavaThread* thread = JavaThread::current();
duke@435 1678 assert(thread->thread_state() == _thread_in_vm, "must be in vm state");
duke@435 1679
duke@435 1680 HandleMark hm(thread);
duke@435 1681 methodHandle mh(thread, method);
duke@435 1682
duke@435 1683 EVT_TRIG_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("JVMTI [%s] Trg Native Method Bind event triggered",
duke@435 1684 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1685
duke@435 1686 if (JvmtiEventController::is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
duke@435 1687 JvmtiEnvIterator it;
duke@435 1688 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1689 if (env->is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
duke@435 1690 EVT_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("JVMTI [%s] Evt Native Method Bind event sent",
duke@435 1691 JvmtiTrace::safe_get_thread_name(thread) ));
duke@435 1692
duke@435 1693 JvmtiMethodEventMark jem(thread, mh);
duke@435 1694 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1695 JNIEnv* jni_env = JvmtiEnv::get_phase() == JVMTI_PHASE_PRIMORDIAL? NULL : jem.jni_env();
duke@435 1696 jvmtiEventNativeMethodBind callback = env->callbacks()->NativeMethodBind;
duke@435 1697 if (callback != NULL) {
duke@435 1698 (*callback)(env->jvmti_external(), jni_env, jem.jni_thread(),
duke@435 1699 jem.jni_methodID(), (void*)(*function_ptr), (void**)function_ptr);
duke@435 1700 }
duke@435 1701 }
duke@435 1702 }
duke@435 1703 }
duke@435 1704 }
duke@435 1705
dcubed@1619 1706 // Returns a record containing inlining information for the given nmethod
dcubed@1619 1707 jvmtiCompiledMethodLoadInlineRecord* create_inline_record(nmethod* nm) {
dcubed@1619 1708 jint numstackframes = 0;
dcubed@1619 1709 jvmtiCompiledMethodLoadInlineRecord* record = (jvmtiCompiledMethodLoadInlineRecord*)NEW_RESOURCE_OBJ(jvmtiCompiledMethodLoadInlineRecord);
dcubed@1619 1710 record->header.kind = JVMTI_CMLR_INLINE_INFO;
dcubed@1619 1711 record->header.next = NULL;
dcubed@1619 1712 record->header.majorinfoversion = JVMTI_CMLR_MAJOR_VERSION_1;
dcubed@1619 1713 record->header.minorinfoversion = JVMTI_CMLR_MINOR_VERSION_0;
dcubed@1619 1714 record->numpcs = 0;
dcubed@1619 1715 for(PcDesc* p = nm->scopes_pcs_begin(); p < nm->scopes_pcs_end(); p++) {
dcubed@1619 1716 if(p->scope_decode_offset() == DebugInformationRecorder::serialized_null) continue;
dcubed@1619 1717 record->numpcs++;
dcubed@1619 1718 }
dcubed@1619 1719 record->pcinfo = (PCStackInfo*)(NEW_RESOURCE_ARRAY(PCStackInfo, record->numpcs));
dcubed@1619 1720 int scope = 0;
dcubed@1619 1721 for(PcDesc* p = nm->scopes_pcs_begin(); p < nm->scopes_pcs_end(); p++) {
dcubed@1619 1722 if(p->scope_decode_offset() == DebugInformationRecorder::serialized_null) continue;
dcubed@1619 1723 void* pc_address = (void*)p->real_pc(nm);
dcubed@1619 1724 assert(pc_address != NULL, "pc_address must be non-null");
dcubed@1619 1725 record->pcinfo[scope].pc = pc_address;
dcubed@1619 1726 numstackframes=0;
dcubed@1619 1727 for(ScopeDesc* sd = nm->scope_desc_at(p->real_pc(nm));sd != NULL;sd = sd->sender()) {
dcubed@1619 1728 numstackframes++;
dcubed@1619 1729 }
dcubed@1619 1730 assert(numstackframes != 0, "numstackframes must be nonzero.");
dcubed@1619 1731 record->pcinfo[scope].methods = (jmethodID *)NEW_RESOURCE_ARRAY(jmethodID, numstackframes);
dcubed@1619 1732 record->pcinfo[scope].bcis = (jint *)NEW_RESOURCE_ARRAY(jint, numstackframes);
dcubed@1619 1733 record->pcinfo[scope].numstackframes = numstackframes;
dcubed@1619 1734 int stackframe = 0;
dcubed@1619 1735 for(ScopeDesc* sd = nm->scope_desc_at(p->real_pc(nm));sd != NULL;sd = sd->sender()) {
dcubed@1619 1736 // sd->method() can be NULL for stubs but not for nmethods. To be completely robust, include an assert that we should never see a null sd->method()
coleenp@4037 1737 assert(sd->method() != NULL, "sd->method() cannot be null.");
dcubed@1619 1738 record->pcinfo[scope].methods[stackframe] = sd->method()->jmethod_id();
dcubed@1619 1739 record->pcinfo[scope].bcis[stackframe] = sd->bci();
dcubed@1619 1740 stackframe++;
dcubed@1619 1741 }
dcubed@1619 1742 scope++;
dcubed@1619 1743 }
dcubed@1619 1744 return record;
dcubed@1619 1745 }
duke@435 1746
duke@435 1747 void JvmtiExport::post_compiled_method_load(nmethod *nm) {
duke@435 1748 JavaThread* thread = JavaThread::current();
duke@435 1749
duke@435 1750 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
duke@435 1751 ("JVMTI [%s] method compile load event triggered",
duke@435 1752 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1753
duke@435 1754 JvmtiEnvIterator it;
duke@435 1755 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1756 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
duke@435 1757
duke@435 1758 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
duke@435 1759 ("JVMTI [%s] class compile method load event sent %s.%s ",
duke@435 1760 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1761 (nm->method() == NULL) ? "NULL" : nm->method()->klass_name()->as_C_string(),
duke@435 1762 (nm->method() == NULL) ? "NULL" : nm->method()->name()->as_C_string()));
duke@435 1763 ResourceMark rm(thread);
kamg@2511 1764 HandleMark hm(thread);
dcubed@1619 1765
dcubed@1619 1766 // Add inlining information
dcubed@1619 1767 jvmtiCompiledMethodLoadInlineRecord* inlinerecord = create_inline_record(nm);
dcubed@1619 1768 // Pass inlining information through the void pointer
dcubed@1619 1769 JvmtiCompiledMethodLoadEventMark jem(thread, nm, inlinerecord);
duke@435 1770 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1771 jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
duke@435 1772 if (callback != NULL) {
duke@435 1773 (*callback)(env->jvmti_external(), jem.jni_methodID(),
duke@435 1774 jem.code_size(), jem.code_data(), jem.map_length(),
duke@435 1775 jem.map(), jem.compile_info());
duke@435 1776 }
duke@435 1777 }
duke@435 1778 }
duke@435 1779 }
duke@435 1780
duke@435 1781
duke@435 1782 // post a COMPILED_METHOD_LOAD event for a given environment
duke@435 1783 void JvmtiExport::post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length,
duke@435 1784 const void *code_begin, const jint map_length,
duke@435 1785 const jvmtiAddrLocationMap* map)
duke@435 1786 {
duke@435 1787 JavaThread* thread = JavaThread::current();
duke@435 1788 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
duke@435 1789 ("JVMTI [%s] method compile load event triggered (by GenerateEvents)",
duke@435 1790 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1791 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
duke@435 1792
duke@435 1793 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
duke@435 1794 ("JVMTI [%s] class compile method load event sent (by GenerateEvents), jmethodID=" PTR_FORMAT,
duke@435 1795 JvmtiTrace::safe_get_thread_name(thread), method));
duke@435 1796
duke@435 1797 JvmtiEventMark jem(thread);
duke@435 1798 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1799 jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
duke@435 1800 if (callback != NULL) {
duke@435 1801 (*callback)(env->jvmti_external(), method,
duke@435 1802 length, code_begin, map_length,
duke@435 1803 map, NULL);
duke@435 1804 }
duke@435 1805 }
duke@435 1806 }
duke@435 1807
duke@435 1808 void JvmtiExport::post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) {
dcubed@2836 1809 assert(name != NULL && name[0] != '\0', "sanity check");
dcubed@2836 1810
duke@435 1811 JavaThread* thread = JavaThread::current();
kamg@2583 1812 // In theory everyone coming thru here is in_vm but we need to be certain
kamg@2583 1813 // because a callee will do a vm->native transition
kamg@2583 1814 ThreadInVMfromUnknown __tiv;
kamg@2583 1815
duke@435 1816 EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
duke@435 1817 ("JVMTI [%s] method dynamic code generated event triggered",
duke@435 1818 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1819 JvmtiEnvIterator it;
duke@435 1820 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1821 if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) {
duke@435 1822 EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
duke@435 1823 ("JVMTI [%s] dynamic code generated event sent for %s",
duke@435 1824 JvmtiTrace::safe_get_thread_name(thread), name));
duke@435 1825 JvmtiEventMark jem(thread);
duke@435 1826 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1827 jint length = (jint)pointer_delta(code_end, code_begin, sizeof(char));
duke@435 1828 jvmtiEventDynamicCodeGenerated callback = env->callbacks()->DynamicCodeGenerated;
duke@435 1829 if (callback != NULL) {
duke@435 1830 (*callback)(env->jvmti_external(), name, (void*)code_begin, length);
duke@435 1831 }
duke@435 1832 }
duke@435 1833 }
duke@435 1834 }
duke@435 1835
duke@435 1836 void JvmtiExport::post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) {
duke@435 1837 jvmtiPhase phase = JvmtiEnv::get_phase();
duke@435 1838 if (phase == JVMTI_PHASE_PRIMORDIAL || phase == JVMTI_PHASE_START) {
duke@435 1839 post_dynamic_code_generated_internal(name, code_begin, code_end);
kamg@2583 1840 } else {
kamg@2583 1841 // It may not be safe to post the event from this thread. Defer all
kamg@2583 1842 // postings to the service thread so that it can perform them in a safe
kamg@2583 1843 // context and in-order.
kamg@2583 1844 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
kamg@2583 1845 JvmtiDeferredEvent event = JvmtiDeferredEvent::dynamic_code_generated_event(
kamg@2583 1846 name, code_begin, code_end);
kamg@2583 1847 JvmtiDeferredEventQueue::enqueue(event);
duke@435 1848 }
duke@435 1849 }
duke@435 1850
duke@435 1851
duke@435 1852 // post a DYNAMIC_CODE_GENERATED event for a given environment
duke@435 1853 // used by GenerateEvents
duke@435 1854 void JvmtiExport::post_dynamic_code_generated(JvmtiEnv* env, const char *name,
duke@435 1855 const void *code_begin, const void *code_end)
duke@435 1856 {
duke@435 1857 JavaThread* thread = JavaThread::current();
duke@435 1858 EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
duke@435 1859 ("JVMTI [%s] dynamic code generated event triggered (by GenerateEvents)",
duke@435 1860 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1861 if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) {
duke@435 1862 EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
duke@435 1863 ("JVMTI [%s] dynamic code generated event sent for %s",
duke@435 1864 JvmtiTrace::safe_get_thread_name(thread), name));
duke@435 1865 JvmtiEventMark jem(thread);
duke@435 1866 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1867 jint length = (jint)pointer_delta(code_end, code_begin, sizeof(char));
duke@435 1868 jvmtiEventDynamicCodeGenerated callback = env->callbacks()->DynamicCodeGenerated;
duke@435 1869 if (callback != NULL) {
duke@435 1870 (*callback)(env->jvmti_external(), name, (void*)code_begin, length);
duke@435 1871 }
duke@435 1872 }
duke@435 1873 }
duke@435 1874
duke@435 1875 // post a DynamicCodeGenerated event while holding locks in the VM.
duke@435 1876 void JvmtiExport::post_dynamic_code_generated_while_holding_locks(const char* name,
duke@435 1877 address code_begin, address code_end)
duke@435 1878 {
duke@435 1879 // register the stub with the current dynamic code event collector
duke@435 1880 JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
dcubed@1044 1881 // state can only be NULL if the current thread is exiting which
dcubed@1044 1882 // should not happen since we're trying to post an event
dcubed@1044 1883 guarantee(state != NULL, "attempt to register stub via an exiting thread");
duke@435 1884 JvmtiDynamicCodeEventCollector* collector = state->get_dynamic_code_event_collector();
duke@435 1885 guarantee(collector != NULL, "attempt to register stub without event collector");
duke@435 1886 collector->register_stub(name, code_begin, code_end);
duke@435 1887 }
duke@435 1888
duke@435 1889 // Collect all the vm internally allocated objects which are visible to java world
duke@435 1890 void JvmtiExport::record_vm_internal_object_allocation(oop obj) {
duke@435 1891 Thread* thread = ThreadLocalStorage::thread();
duke@435 1892 if (thread != NULL && thread->is_Java_thread()) {
duke@435 1893 // Can not take safepoint here.
duke@435 1894 No_Safepoint_Verifier no_sfpt;
duke@435 1895 // Can not take safepoint here so can not use state_for to get
duke@435 1896 // jvmti thread state.
duke@435 1897 JvmtiThreadState *state = ((JavaThread*)thread)->jvmti_thread_state();
duke@435 1898 if (state != NULL ) {
duke@435 1899 // state is non NULL when VMObjectAllocEventCollector is enabled.
duke@435 1900 JvmtiVMObjectAllocEventCollector *collector;
duke@435 1901 collector = state->get_vm_object_alloc_event_collector();
duke@435 1902 if (collector != NULL && collector->is_enabled()) {
duke@435 1903 // Don't record classes as these will be notified via the ClassLoad
duke@435 1904 // event.
never@1577 1905 if (obj->klass() != SystemDictionary::Class_klass()) {
duke@435 1906 collector->record_allocation(obj);
duke@435 1907 }
duke@435 1908 }
duke@435 1909 }
duke@435 1910 }
duke@435 1911 }
duke@435 1912
duke@435 1913 void JvmtiExport::post_garbage_collection_finish() {
duke@435 1914 Thread *thread = Thread::current(); // this event is posted from VM-Thread.
duke@435 1915 EVT_TRIG_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH,
duke@435 1916 ("JVMTI [%s] garbage collection finish event triggered",
duke@435 1917 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1918 JvmtiEnvIterator it;
duke@435 1919 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1920 if (env->is_enabled(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH)) {
duke@435 1921 EVT_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH,
duke@435 1922 ("JVMTI [%s] garbage collection finish event sent ",
duke@435 1923 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1924 JvmtiThreadEventTransition jet(thread);
duke@435 1925 // JNIEnv is NULL here because this event is posted from VM Thread
duke@435 1926 jvmtiEventGarbageCollectionFinish callback = env->callbacks()->GarbageCollectionFinish;
duke@435 1927 if (callback != NULL) {
duke@435 1928 (*callback)(env->jvmti_external());
duke@435 1929 }
duke@435 1930 }
duke@435 1931 }
duke@435 1932 }
duke@435 1933
duke@435 1934 void JvmtiExport::post_garbage_collection_start() {
duke@435 1935 Thread* thread = Thread::current(); // this event is posted from vm-thread.
duke@435 1936 EVT_TRIG_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_START,
duke@435 1937 ("JVMTI [%s] garbage collection start event triggered",
duke@435 1938 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1939 JvmtiEnvIterator it;
duke@435 1940 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1941 if (env->is_enabled(JVMTI_EVENT_GARBAGE_COLLECTION_START)) {
duke@435 1942 EVT_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_START,
duke@435 1943 ("JVMTI [%s] garbage collection start event sent ",
duke@435 1944 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1945 JvmtiThreadEventTransition jet(thread);
duke@435 1946 // JNIEnv is NULL here because this event is posted from VM Thread
duke@435 1947 jvmtiEventGarbageCollectionStart callback = env->callbacks()->GarbageCollectionStart;
duke@435 1948 if (callback != NULL) {
duke@435 1949 (*callback)(env->jvmti_external());
duke@435 1950 }
duke@435 1951 }
duke@435 1952 }
duke@435 1953 }
duke@435 1954
duke@435 1955 void JvmtiExport::post_data_dump() {
duke@435 1956 Thread *thread = Thread::current();
duke@435 1957 EVT_TRIG_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST,
duke@435 1958 ("JVMTI [%s] data dump request event triggered",
duke@435 1959 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1960 JvmtiEnvIterator it;
duke@435 1961 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1962 if (env->is_enabled(JVMTI_EVENT_DATA_DUMP_REQUEST)) {
duke@435 1963 EVT_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST,
duke@435 1964 ("JVMTI [%s] data dump request event sent ",
duke@435 1965 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1966 JvmtiThreadEventTransition jet(thread);
duke@435 1967 // JNIEnv is NULL here because this event is posted from VM Thread
duke@435 1968 jvmtiEventDataDumpRequest callback = env->callbacks()->DataDumpRequest;
duke@435 1969 if (callback != NULL) {
duke@435 1970 (*callback)(env->jvmti_external());
duke@435 1971 }
duke@435 1972 }
duke@435 1973 }
duke@435 1974 }
duke@435 1975
duke@435 1976 void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) {
duke@435 1977 oop object = (oop)obj_mntr->object();
duke@435 1978 if (!ServiceUtil::visible_oop(object)) {
duke@435 1979 // Ignore monitor contended enter for vm internal object.
duke@435 1980 return;
duke@435 1981 }
duke@435 1982 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1983 if (state == NULL) {
duke@435 1984 return;
duke@435 1985 }
duke@435 1986
duke@435 1987 HandleMark hm(thread);
duke@435 1988 Handle h(thread, object);
duke@435 1989
duke@435 1990 EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
duke@435 1991 ("JVMTI [%s] montior contended enter event triggered",
duke@435 1992 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1993
duke@435 1994 JvmtiEnvThreadStateIterator it(state);
duke@435 1995 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1996 if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTER)) {
duke@435 1997 EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
duke@435 1998 ("JVMTI [%s] monitor contended enter event sent",
duke@435 1999 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2000 JvmtiMonitorEventMark jem(thread, h());
duke@435 2001 JvmtiEnv *env = ets->get_env();
duke@435 2002 JvmtiThreadEventTransition jet(thread);
duke@435 2003 jvmtiEventMonitorContendedEnter callback = env->callbacks()->MonitorContendedEnter;
duke@435 2004 if (callback != NULL) {
duke@435 2005 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
duke@435 2006 }
duke@435 2007 }
duke@435 2008 }
duke@435 2009 }
duke@435 2010
duke@435 2011 void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) {
duke@435 2012 oop object = (oop)obj_mntr->object();
duke@435 2013 if (!ServiceUtil::visible_oop(object)) {
duke@435 2014 // Ignore monitor contended entered for vm internal object.
duke@435 2015 return;
duke@435 2016 }
duke@435 2017 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 2018 if (state == NULL) {
duke@435 2019 return;
duke@435 2020 }
duke@435 2021
duke@435 2022 HandleMark hm(thread);
duke@435 2023 Handle h(thread, object);
duke@435 2024
duke@435 2025 EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
duke@435 2026 ("JVMTI [%s] montior contended entered event triggered",
duke@435 2027 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2028
duke@435 2029 JvmtiEnvThreadStateIterator it(state);
duke@435 2030 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 2031 if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)) {
duke@435 2032 EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
duke@435 2033 ("JVMTI [%s] monitor contended enter event sent",
duke@435 2034 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2035 JvmtiMonitorEventMark jem(thread, h());
duke@435 2036 JvmtiEnv *env = ets->get_env();
duke@435 2037 JvmtiThreadEventTransition jet(thread);
duke@435 2038 jvmtiEventMonitorContendedEntered callback = env->callbacks()->MonitorContendedEntered;
duke@435 2039 if (callback != NULL) {
duke@435 2040 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
duke@435 2041 }
duke@435 2042 }
duke@435 2043 }
duke@435 2044 }
duke@435 2045
duke@435 2046 void JvmtiExport::post_monitor_wait(JavaThread *thread, oop object,
duke@435 2047 jlong timeout) {
duke@435 2048 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 2049 if (state == NULL) {
duke@435 2050 return;
duke@435 2051 }
duke@435 2052
duke@435 2053 HandleMark hm(thread);
duke@435 2054 Handle h(thread, object);
duke@435 2055
duke@435 2056 EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAIT,
duke@435 2057 ("JVMTI [%s] montior wait event triggered",
duke@435 2058 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2059
duke@435 2060 JvmtiEnvThreadStateIterator it(state);
duke@435 2061 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 2062 if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAIT)) {
duke@435 2063 EVT_TRACE(JVMTI_EVENT_MONITOR_WAIT,
duke@435 2064 ("JVMTI [%s] monitor wait event sent ",
duke@435 2065 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2066 JvmtiMonitorEventMark jem(thread, h());
duke@435 2067 JvmtiEnv *env = ets->get_env();
duke@435 2068 JvmtiThreadEventTransition jet(thread);
duke@435 2069 jvmtiEventMonitorWait callback = env->callbacks()->MonitorWait;
duke@435 2070 if (callback != NULL) {
duke@435 2071 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 2072 jem.jni_object(), timeout);
duke@435 2073 }
duke@435 2074 }
duke@435 2075 }
duke@435 2076 }
duke@435 2077
duke@435 2078 void JvmtiExport::post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) {
duke@435 2079 oop object = (oop)obj_mntr->object();
duke@435 2080 if (!ServiceUtil::visible_oop(object)) {
duke@435 2081 // Ignore monitor waited for vm internal object.
duke@435 2082 return;
duke@435 2083 }
duke@435 2084 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 2085 if (state == NULL) {
duke@435 2086 return;
duke@435 2087 }
duke@435 2088
duke@435 2089 HandleMark hm(thread);
duke@435 2090 Handle h(thread, object);
duke@435 2091
duke@435 2092 EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAITED,
duke@435 2093 ("JVMTI [%s] montior waited event triggered",
duke@435 2094 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2095
duke@435 2096 JvmtiEnvThreadStateIterator it(state);
duke@435 2097 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 2098 if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) {
duke@435 2099 EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED,
duke@435 2100 ("JVMTI [%s] monitor waited event sent ",
duke@435 2101 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2102 JvmtiMonitorEventMark jem(thread, h());
duke@435 2103 JvmtiEnv *env = ets->get_env();
duke@435 2104 JvmtiThreadEventTransition jet(thread);
duke@435 2105 jvmtiEventMonitorWaited callback = env->callbacks()->MonitorWaited;
duke@435 2106 if (callback != NULL) {
duke@435 2107 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 2108 jem.jni_object(), timed_out);
duke@435 2109 }
duke@435 2110 }
duke@435 2111 }
duke@435 2112 }
duke@435 2113
duke@435 2114
duke@435 2115 void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
duke@435 2116 EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("JVMTI [%s] Trg vm object alloc triggered",
duke@435 2117 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2118 if (object == NULL) {
duke@435 2119 return;
duke@435 2120 }
duke@435 2121 HandleMark hm(thread);
duke@435 2122 Handle h(thread, object);
duke@435 2123 JvmtiEnvIterator it;
duke@435 2124 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 2125 if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC)) {
duke@435 2126 EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("JVMTI [%s] Evt vmobject alloc sent %s",
duke@435 2127 JvmtiTrace::safe_get_thread_name(thread),
hseigel@4278 2128 object==NULL? "NULL" : java_lang_Class::as_Klass(object)->external_name()));
duke@435 2129
duke@435 2130 JvmtiVMObjectAllocEventMark jem(thread, h());
duke@435 2131 JvmtiJavaThreadEventTransition jet(thread);
duke@435 2132 jvmtiEventVMObjectAlloc callback = env->callbacks()->VMObjectAlloc;
duke@435 2133 if (callback != NULL) {
duke@435 2134 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 2135 jem.jni_jobject(), jem.jni_class(), jem.size());
duke@435 2136 }
duke@435 2137 }
duke@435 2138 }
duke@435 2139 }
duke@435 2140
duke@435 2141 ////////////////////////////////////////////////////////////////////////////////////////////////
duke@435 2142
duke@435 2143 void JvmtiExport::cleanup_thread(JavaThread* thread) {
duke@435 2144 assert(JavaThread::current() == thread, "thread is not current");
kamg@2446 2145 MutexLocker mu(JvmtiThreadState_lock);
duke@435 2146
kamg@2446 2147 if (thread->jvmti_thread_state() != NULL) {
kamg@2446 2148 // This has to happen after the thread state is removed, which is
kamg@2446 2149 // why it is not in post_thread_end_event like its complement
kamg@2446 2150 // Maybe both these functions should be rolled into the posts?
kamg@2446 2151 JvmtiEventController::thread_ended(thread);
kamg@2446 2152 }
duke@435 2153 }
duke@435 2154
duke@435 2155 void JvmtiExport::oops_do(OopClosure* f) {
duke@435 2156 JvmtiCurrentBreakpoints::oops_do(f);
duke@435 2157 JvmtiVMObjectAllocEventCollector::oops_do_for_all_threads(f);
duke@435 2158 }
duke@435 2159
kamg@2467 2160 void JvmtiExport::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f) {
kamg@2467 2161 JvmtiTagMap::weak_oops_do(is_alive, f);
kamg@2467 2162 }
kamg@2467 2163
kamg@2467 2164 void JvmtiExport::gc_epilogue() {
kamg@2467 2165 JvmtiCurrentBreakpoints::gc_epilogue();
kamg@2467 2166 }
kamg@2467 2167
duke@435 2168 // Onload raw monitor transition.
duke@435 2169 void JvmtiExport::transition_pending_onload_raw_monitors() {
duke@435 2170 JvmtiPendingMonitors::transition_raw_monitors();
duke@435 2171 }
duke@435 2172
duke@435 2173 ////////////////////////////////////////////////////////////////////////////////////////////////
duke@435 2174
duke@435 2175 // type for the Agent_OnAttach entry point
duke@435 2176 extern "C" {
duke@435 2177 typedef jint (JNICALL *OnAttachEntry_t)(JavaVM*, char *, void *);
duke@435 2178 }
duke@435 2179
duke@435 2180 jint JvmtiExport::load_agent_library(AttachOperation* op, outputStream* st) {
duke@435 2181 char ebuf[1024];
duke@435 2182 char buffer[JVM_MAXPATHLEN];
bpittore@4261 2183 void* library = NULL;
duke@435 2184 jint result = JNI_ERR;
duke@435 2185
duke@435 2186 // get agent name and options
duke@435 2187 const char* agent = op->arg(0);
duke@435 2188 const char* absParam = op->arg(1);
duke@435 2189 const char* options = op->arg(2);
duke@435 2190
duke@435 2191 // The abs paramter should be "true" or "false"
duke@435 2192 bool is_absolute_path = (absParam != NULL) && (strcmp(absParam,"true")==0);
duke@435 2193
duke@435 2194
duke@435 2195 // If the path is absolute we attempt to load the library. Otherwise we try to
duke@435 2196 // load it from the standard dll directory.
duke@435 2197
duke@435 2198 if (is_absolute_path) {
ikrylov@2322 2199 library = os::dll_load(agent, ebuf, sizeof ebuf);
duke@435 2200 } else {
duke@435 2201 // Try to load the agent from the standard dll directory
bpittore@4261 2202 if (os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
bpittore@4261 2203 agent)) {
bpittore@4261 2204 library = os::dll_load(buffer, ebuf, sizeof ebuf);
bpittore@4261 2205 }
duke@435 2206 if (library == NULL) {
duke@435 2207 // not found - try local path
duke@435 2208 char ns[1] = {0};
bpittore@4261 2209 if (os::dll_build_name(buffer, sizeof(buffer), ns, agent)) {
bpittore@4261 2210 library = os::dll_load(buffer, ebuf, sizeof ebuf);
bpittore@4261 2211 }
duke@435 2212 }
duke@435 2213 }
duke@435 2214
duke@435 2215 // If the library was loaded then we attempt to invoke the Agent_OnAttach
duke@435 2216 // function
duke@435 2217 if (library != NULL) {
duke@435 2218
duke@435 2219 // Lookup the Agent_OnAttach function
duke@435 2220 OnAttachEntry_t on_attach_entry = NULL;
duke@435 2221 const char *on_attach_symbols[] = AGENT_ONATTACH_SYMBOLS;
duke@435 2222 for (uint symbol_index = 0; symbol_index < ARRAY_SIZE(on_attach_symbols); symbol_index++) {
duke@435 2223 on_attach_entry =
ikrylov@2322 2224 CAST_TO_FN_PTR(OnAttachEntry_t, os::dll_lookup(library, on_attach_symbols[symbol_index]));
duke@435 2225 if (on_attach_entry != NULL) break;
duke@435 2226 }
duke@435 2227
duke@435 2228 if (on_attach_entry == NULL) {
duke@435 2229 // Agent_OnAttach missing - unload library
ikrylov@2322 2230 os::dll_unload(library);
duke@435 2231 } else {
duke@435 2232 // Invoke the Agent_OnAttach function
duke@435 2233 JavaThread* THREAD = JavaThread::current();
duke@435 2234 {
duke@435 2235 extern struct JavaVM_ main_vm;
duke@435 2236 JvmtiThreadEventMark jem(THREAD);
duke@435 2237 JvmtiJavaThreadEventTransition jet(THREAD);
duke@435 2238
duke@435 2239 result = (*on_attach_entry)(&main_vm, (char*)options, NULL);
duke@435 2240 }
duke@435 2241
duke@435 2242 // Agent_OnAttach may have used JNI
duke@435 2243 if (HAS_PENDING_EXCEPTION) {
duke@435 2244 CLEAR_PENDING_EXCEPTION;
duke@435 2245 }
duke@435 2246
duke@435 2247 // If OnAttach returns JNI_OK then we add it to the list of
duke@435 2248 // agent libraries so that we can call Agent_OnUnload later.
duke@435 2249 if (result == JNI_OK) {
duke@435 2250 Arguments::add_loaded_agent(agent, (char*)options, is_absolute_path, library);
duke@435 2251 }
duke@435 2252
duke@435 2253 // Agent_OnAttach executed so completion status is JNI_OK
duke@435 2254 st->print_cr("%d", result);
duke@435 2255 result = JNI_OK;
duke@435 2256 }
duke@435 2257 }
duke@435 2258 return result;
duke@435 2259 }
duke@435 2260
duke@435 2261 ////////////////////////////////////////////////////////////////////////////////////////////////
duke@435 2262
duke@435 2263 // Setup current current thread for event collection.
duke@435 2264 void JvmtiEventCollector::setup_jvmti_thread_state() {
duke@435 2265 // set this event collector to be the current one.
duke@435 2266 JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
dcubed@1044 2267 // state can only be NULL if the current thread is exiting which
dcubed@1044 2268 // should not happen since we're trying to configure for event collection
dcubed@1044 2269 guarantee(state != NULL, "exiting thread called setup_jvmti_thread_state");
duke@435 2270 if (is_vm_object_alloc_event()) {
duke@435 2271 _prev = state->get_vm_object_alloc_event_collector();
duke@435 2272 state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)this);
duke@435 2273 } else if (is_dynamic_code_event()) {
duke@435 2274 _prev = state->get_dynamic_code_event_collector();
duke@435 2275 state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)this);
duke@435 2276 }
duke@435 2277 }
duke@435 2278
duke@435 2279 // Unset current event collection in this thread and reset it with previous
duke@435 2280 // collector.
duke@435 2281 void JvmtiEventCollector::unset_jvmti_thread_state() {
duke@435 2282 JvmtiThreadState* state = JavaThread::current()->jvmti_thread_state();
duke@435 2283 if (state != NULL) {
duke@435 2284 // restore the previous event collector (if any)
duke@435 2285 if (is_vm_object_alloc_event()) {
duke@435 2286 if (state->get_vm_object_alloc_event_collector() == this) {
duke@435 2287 state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)_prev);
duke@435 2288 } else {
duke@435 2289 // this thread's jvmti state was created during the scope of
duke@435 2290 // the event collector.
duke@435 2291 }
duke@435 2292 } else {
duke@435 2293 if (is_dynamic_code_event()) {
duke@435 2294 if (state->get_dynamic_code_event_collector() == this) {
duke@435 2295 state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)_prev);
duke@435 2296 } else {
duke@435 2297 // this thread's jvmti state was created during the scope of
duke@435 2298 // the event collector.
duke@435 2299 }
duke@435 2300 }
duke@435 2301 }
duke@435 2302 }
duke@435 2303 }
duke@435 2304
duke@435 2305 // create the dynamic code event collector
duke@435 2306 JvmtiDynamicCodeEventCollector::JvmtiDynamicCodeEventCollector() : _code_blobs(NULL) {
duke@435 2307 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@435 2308 setup_jvmti_thread_state();
duke@435 2309 }
duke@435 2310 }
duke@435 2311
duke@435 2312 // iterate over any code blob descriptors collected and post a
duke@435 2313 // DYNAMIC_CODE_GENERATED event to the profiler.
duke@435 2314 JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
duke@435 2315 assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
duke@435 2316 // iterate over any code blob descriptors that we collected
duke@435 2317 if (_code_blobs != NULL) {
duke@435 2318 for (int i=0; i<_code_blobs->length(); i++) {
duke@435 2319 JvmtiCodeBlobDesc* blob = _code_blobs->at(i);
duke@435 2320 JvmtiExport::post_dynamic_code_generated(blob->name(), blob->code_begin(), blob->code_end());
duke@435 2321 FreeHeap(blob);
duke@435 2322 }
duke@435 2323 delete _code_blobs;
duke@435 2324 }
duke@435 2325 unset_jvmti_thread_state();
duke@435 2326 }
duke@435 2327
duke@435 2328 // register a stub
duke@435 2329 void JvmtiDynamicCodeEventCollector::register_stub(const char* name, address start, address end) {
duke@435 2330 if (_code_blobs == NULL) {
zgu@3900 2331 _code_blobs = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JvmtiCodeBlobDesc*>(1,true);
duke@435 2332 }
duke@435 2333 _code_blobs->append(new JvmtiCodeBlobDesc(name, start, end));
duke@435 2334 }
duke@435 2335
duke@435 2336 // Setup current thread to record vm allocated objects.
duke@435 2337 JvmtiVMObjectAllocEventCollector::JvmtiVMObjectAllocEventCollector() : _allocated(NULL) {
duke@435 2338 if (JvmtiExport::should_post_vm_object_alloc()) {
duke@435 2339 _enable = true;
duke@435 2340 setup_jvmti_thread_state();
duke@435 2341 } else {
duke@435 2342 _enable = false;
duke@435 2343 }
duke@435 2344 }
duke@435 2345
duke@435 2346 // Post vm_object_alloc event for vm allocated objects visible to java
duke@435 2347 // world.
duke@435 2348 JvmtiVMObjectAllocEventCollector::~JvmtiVMObjectAllocEventCollector() {
duke@435 2349 if (_allocated != NULL) {
duke@435 2350 set_enabled(false);
duke@435 2351 for (int i = 0; i < _allocated->length(); i++) {
duke@435 2352 oop obj = _allocated->at(i);
duke@435 2353 if (ServiceUtil::visible_oop(obj)) {
duke@435 2354 JvmtiExport::post_vm_object_alloc(JavaThread::current(), obj);
duke@435 2355 }
duke@435 2356 }
duke@435 2357 delete _allocated;
duke@435 2358 }
duke@435 2359 unset_jvmti_thread_state();
duke@435 2360 }
duke@435 2361
duke@435 2362 void JvmtiVMObjectAllocEventCollector::record_allocation(oop obj) {
duke@435 2363 assert(is_enabled(), "VM object alloc event collector is not enabled");
duke@435 2364 if (_allocated == NULL) {
zgu@3900 2365 _allocated = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(1, true);
duke@435 2366 }
duke@435 2367 _allocated->push(obj);
duke@435 2368 }
duke@435 2369
duke@435 2370 // GC support.
duke@435 2371 void JvmtiVMObjectAllocEventCollector::oops_do(OopClosure* f) {
duke@435 2372 if (_allocated != NULL) {
duke@435 2373 for(int i=_allocated->length() - 1; i >= 0; i--) {
duke@435 2374 if (_allocated->at(i) != NULL) {
duke@435 2375 f->do_oop(_allocated->adr_at(i));
duke@435 2376 }
duke@435 2377 }
duke@435 2378 }
duke@435 2379 }
duke@435 2380
duke@435 2381 void JvmtiVMObjectAllocEventCollector::oops_do_for_all_threads(OopClosure* f) {
duke@435 2382 // no-op if jvmti not enabled
duke@435 2383 if (!JvmtiEnv::environments_might_exist()) {
duke@435 2384 return;
duke@435 2385 }
duke@435 2386
duke@435 2387 // Runs at safepoint. So no need to acquire Threads_lock.
duke@435 2388 for (JavaThread *jthr = Threads::first(); jthr != NULL; jthr = jthr->next()) {
duke@435 2389 JvmtiThreadState *state = jthr->jvmti_thread_state();
duke@435 2390 if (state != NULL) {
duke@435 2391 JvmtiVMObjectAllocEventCollector *collector;
duke@435 2392 collector = state->get_vm_object_alloc_event_collector();
duke@435 2393 while (collector != NULL) {
duke@435 2394 collector->oops_do(f);
duke@435 2395 collector = (JvmtiVMObjectAllocEventCollector *)collector->get_prev();
duke@435 2396 }
duke@435 2397 }
duke@435 2398 }
duke@435 2399 }
duke@435 2400
duke@435 2401
duke@435 2402 // Disable collection of VMObjectAlloc events
duke@435 2403 NoJvmtiVMObjectAllocMark::NoJvmtiVMObjectAllocMark() : _collector(NULL) {
duke@435 2404 // a no-op if VMObjectAlloc event is not enabled
duke@435 2405 if (!JvmtiExport::should_post_vm_object_alloc()) {
duke@435 2406 return;
duke@435 2407 }
duke@435 2408 Thread* thread = ThreadLocalStorage::thread();
duke@435 2409 if (thread != NULL && thread->is_Java_thread()) {
duke@435 2410 JavaThread* current_thread = (JavaThread*)thread;
duke@435 2411 JvmtiThreadState *state = current_thread->jvmti_thread_state();
duke@435 2412 if (state != NULL) {
duke@435 2413 JvmtiVMObjectAllocEventCollector *collector;
duke@435 2414 collector = state->get_vm_object_alloc_event_collector();
duke@435 2415 if (collector != NULL && collector->is_enabled()) {
duke@435 2416 _collector = collector;
duke@435 2417 _collector->set_enabled(false);
duke@435 2418 }
duke@435 2419 }
duke@435 2420 }
duke@435 2421 }
duke@435 2422
duke@435 2423 // Re-Enable collection of VMObjectAlloc events (if previously enabled)
duke@435 2424 NoJvmtiVMObjectAllocMark::~NoJvmtiVMObjectAllocMark() {
duke@435 2425 if (was_enabled()) {
duke@435 2426 _collector->set_enabled(true);
duke@435 2427 }
duke@435 2428 };
duke@435 2429
kamg@2445 2430 JvmtiGCMarker::JvmtiGCMarker() {
duke@435 2431 // if there aren't any JVMTI environments then nothing to do
duke@435 2432 if (!JvmtiEnv::environments_might_exist()) {
duke@435 2433 return;
duke@435 2434 }
duke@435 2435
duke@435 2436 if (JvmtiExport::should_post_garbage_collection_start()) {
duke@435 2437 JvmtiExport::post_garbage_collection_start();
duke@435 2438 }
duke@435 2439
kamg@2445 2440 if (SafepointSynchronize::is_at_safepoint()) {
kamg@2445 2441 // Do clean up tasks that need to be done at a safepoint
kamg@2445 2442 JvmtiEnvBase::check_for_periodic_clean_up();
duke@435 2443 }
duke@435 2444 }
duke@435 2445
duke@435 2446 JvmtiGCMarker::~JvmtiGCMarker() {
duke@435 2447 // if there aren't any JVMTI environments then nothing to do
duke@435 2448 if (!JvmtiEnv::environments_might_exist()) {
duke@435 2449 return;
duke@435 2450 }
duke@435 2451
duke@435 2452 // JVMTI notify gc finish
duke@435 2453 if (JvmtiExport::should_post_garbage_collection_finish()) {
duke@435 2454 JvmtiExport::post_garbage_collection_finish();
duke@435 2455 }
duke@435 2456 }

mercurial