--- old/src/hotspot/share/prims/jvmtiThreadState.inline.hpp Wed Nov 8 09:06:04 2017 +++ new/src/hotspot/share/prims/jvmtiThreadState.inline.hpp Wed Nov 8 09:06:03 2017 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -68,4 +68,31 @@ _head_env_thread_state = ets; } +inline JvmtiThreadState* JvmtiThreadState::state_for_while_locked(JavaThread *thread) { + assert(JvmtiThreadState_lock->is_locked(), "sanity check"); + + JvmtiThreadState *state = thread->jvmti_thread_state(); + if (state == NULL) { + if (thread->is_exiting()) { + // don't add a JvmtiThreadState to a thread that is exiting + return NULL; + } + + state = new JvmtiThreadState(thread); + } + return state; +} + +inline JvmtiThreadState* JvmtiThreadState::state_for(JavaThread *thread) { + JvmtiThreadState *state = thread->jvmti_thread_state(); + if (state == NULL) { + MutexLocker mu(JvmtiThreadState_lock); + // check again with the lock held + state = state_for_while_locked(thread); + } else { + CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); + } + return state; +} + #endif // SHARE_VM_PRIMS_JVMTITHREADSTATE_INLINE_HPP