Skip to content

Commit 3a11009

Browse files
committed
8256830: misc tests failed with "assert(env->is_enabled(JVMTI_EVENT_OBJECT_FREE)) failed: checking"
Reviewed-by: kbarrett, sspitsyn, dholmes
1 parent c859fb0 commit 3a11009

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/hotspot/share/prims/jvmtiEventController.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ class JvmtiEventControllerPrivate : public AllStatic {
307307
static void trace_changed(jlong now_enabled, jlong changed);
308308

309309
static void flush_object_free_events(JvmtiEnvBase *env);
310+
static void set_enabled_events_with_lock(JvmtiEnvBase *env, jlong now_enabled);
310311
};
311312

312313
bool JvmtiEventControllerPrivate::_initialized = false;
@@ -409,6 +410,19 @@ JvmtiEventControllerPrivate::flush_object_free_events(JvmtiEnvBase* env) {
409410
}
410411
}
411412

413+
void
414+
JvmtiEventControllerPrivate::set_enabled_events_with_lock(JvmtiEnvBase* env, jlong now_enabled) {
415+
// The state for ObjectFree events must be enabled or disabled
416+
// under the TagMap lock, to allow pending object posting events to complete.
417+
JvmtiTagMap* tag_map = env->tag_map_acquire();
418+
if (tag_map != NULL) {
419+
MutexLocker ml(tag_map->lock(), Mutex::_no_safepoint_check_flag);
420+
env->env_event_enable()->_event_enabled.set_bits(now_enabled);
421+
} else {
422+
env->env_event_enable()->_event_enabled.set_bits(now_enabled);
423+
}
424+
}
425+
412426
// For the specified env: compute the currently truly enabled events
413427
// set external state accordingly.
414428
// Return value and set value must include all events.
@@ -442,8 +456,8 @@ JvmtiEventControllerPrivate::recompute_env_enabled(JvmtiEnvBase* env) {
442456
break;
443457
}
444458

445-
// will we really send these events to this env
446-
env->env_event_enable()->_event_enabled.set_bits(now_enabled);
459+
// Set/reset the event enabled under the tagmap lock.
460+
set_enabled_events_with_lock(env, now_enabled);
447461

448462
trace_changed(now_enabled, (now_enabled ^ was_enabled) & ~THREAD_FILTERED_EVENT_BITS);
449463

src/hotspot/share/prims/jvmtiTagMap.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ void JvmtiTagMap::iterate_through_heap(jint heap_filter,
11581158
void JvmtiTagMap::remove_dead_entries_locked(bool post_object_free) {
11591159
assert(is_locked(), "precondition");
11601160
if (_needs_cleaning) {
1161+
// Recheck whether to post object free events under the lock.
1162+
post_object_free = post_object_free && env()->is_enabled(JVMTI_EVENT_OBJECT_FREE);
11611163
log_info(jvmti, table)("TagMap table needs cleaning%s",
11621164
(post_object_free ? " and posting" : ""));
11631165
hashmap()->remove_dead_entries(env(), post_object_free);

src/hotspot/share/prims/jvmtiTagMap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class JvmtiTagMap : public CHeapObj<mtInternal> {
4949
JvmtiTagMap(JvmtiEnv* env);
5050

5151
// accessors
52-
inline Mutex* lock() { return &_lock; }
5352
inline JvmtiEnv* env() const { return _env; }
5453

5554
void check_hashmap(bool post_events);
@@ -60,6 +59,7 @@ class JvmtiTagMap : public CHeapObj<mtInternal> {
6059
public:
6160
// indicates if this tag map is locked
6261
bool is_locked() { return lock()->is_locked(); }
62+
inline Mutex* lock() { return &_lock; }
6363

6464
JvmtiTagMapTable* hashmap() { return _hashmap; }
6565

0 commit comments

Comments
 (0)