changeset 51688:01316e7ac1d1

8204691: HeapRegion.apply_to_marked_objects_other_vm_test fails with assert(!hr->is_free() || hr->is_empty()) failed: Free region 0 is not empty for set Free list # Summary: Run test in safepoint. Reviewed-by: tschatzl, ehelin
author kbarrett
date Tue, 10 Jul 2018 13:34:32 -0400
parents 510ac4c08610
children 2a89e80301b1
files test/hotspot/gtest/gc/g1/test_heapRegion.cpp
diffstat 1 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/gtest/gc/g1/test_heapRegion.cpp	Tue Jul 10 15:33:55 2018 +0200
+++ b/test/hotspot/gtest/gc/g1/test_heapRegion.cpp	Tue Jul 10 13:34:32 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, 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
@@ -27,6 +27,9 @@
 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
 #include "gc/g1/heapRegion.inline.hpp"
 #include "gc/shared/referenceProcessor.hpp"
+#include "runtime/interfaceSupport.inline.hpp"
+#include "runtime/vm_operations.hpp"
+#include "runtime/vmThread.hpp"
 #include "unittest.hpp"
 
 class VerifyAndCountMarkClosure : public StackObj {
@@ -60,11 +63,12 @@
 #define MARK_OFFSET_2 ( 99 * MinObjAlignment)
 #define MARK_OFFSET_3 (337 * MinObjAlignment)
 
-TEST_OTHER_VM(HeapRegion, apply_to_marked_objects) {
-  if (!UseG1GC) {
-    return;
-  }
+class VM_HeapRegionApplyToMarkedObjectsTest : public VM_GTestExecuteAtSafepoint {
+public:
+  void doit();
+};
 
+void VM_HeapRegionApplyToMarkedObjectsTest::doit() {
   G1CollectedHeap* heap = G1CollectedHeap::heap();
 
   // Using region 0 for testing.
@@ -80,6 +84,8 @@
 
   VerifyAndCountMarkClosure cl(bitmap);
 
+  HeapWord* old_top = region->top();
+
   // When top is equal to bottom the closure should not be
   // applied to any object because apply_to_marked_objects
   // will stop at HeapRegion::scan_limit which is equal to top.
@@ -112,5 +118,19 @@
   region->apply_to_marked_objects(bitmap, &cl);
   EXPECT_EQ(4, cl.count());
   cl.reset();
+
+  region->set_top(old_top);
 }
 
+TEST_VM(HeapRegion, apply_to_marked_object) {
+  if (!UseG1GC) {
+    return;
+  }
+
+  // Run the test in our very own safepoint, because otherwise it
+  // modifies a region behind the back of a possibly using allocation
+  // or running GC.
+  VM_HeapRegionApplyToMarkedObjectsTest op;
+  ThreadInVMfromNative invm(JavaThread::current());
+  VMThread::execute(&op);
+}