src/hotspot/share/oops/cpCache.cpp
changeset 48784 899b522ed65c
parent 48463 474cec233fb2
child 48819 ee513596f3ee
--- a/src/hotspot/share/oops/cpCache.cpp	Fri Jan 12 16:19:56 2018 +0100
+++ b/src/hotspot/share/oops/cpCache.cpp	Wed Jan 10 22:43:42 2018 +0100
@@ -33,6 +33,7 @@
 #include "memory/metaspaceClosure.hpp"
 #include "memory/resourceArea.hpp"
 #include "memory/universe.inline.hpp"
+#include "oops/access.inline.hpp"
 #include "oops/cpCache.hpp"
 #include "oops/objArrayOop.inline.hpp"
 #include "oops/oop.inline.hpp"
@@ -753,13 +754,16 @@
 
 #if INCLUDE_CDS_JAVA_HEAP
 oop ConstantPoolCache::archived_references() {
-  assert(UseSharedSpaces, "UseSharedSpaces expected.");
-  return oopDesc::decode_heap_oop(_archived_references);
+  // Loading an archive root forces the oop to become strongly reachable.
+  // For example, if it is loaded during concurrent marking in a SATB
+  // collector, it will be enqueued to the SATB queue, effectively
+  // shading the previously white object gray.
+  return RootAccess<IN_ARCHIVE_ROOT>::oop_load(&_archived_references);
 }
 
 void ConstantPoolCache::set_archived_references(oop o) {
   assert(DumpSharedSpaces, "called only during runtime");
-  _archived_references = oopDesc::encode_heap_oop(o);
+  RootAccess<IN_ARCHIVE_ROOT>::oop_store(&_archived_references, o);
 }
 #endif