Skip to content
Permalink
Browse files
8271014: Refactor HeapShared::is_archived_object()
Reviewed-by: ccheung, minqi
  • Loading branch information
iklam committed Jul 21, 2021
1 parent ddce47c commit 024c4027d8b0821612e8e82e732182de9192b3fe
@@ -39,6 +39,7 @@
#include "oops/compressedOops.inline.hpp"
#include "runtime/arguments.hpp"
#include "utilities/bitMap.inline.hpp"
#include "utilities/formatBuffer.hpp"

CHeapBitMap* ArchivePtrMarker::_ptrmap = NULL;
VirtualSpace* ArchivePtrMarker::_vs;
@@ -116,6 +116,14 @@ GrowableArrayCHeap<oop, mtClassShared>* HeapShared::_pending_roots = NULL;
narrowOop HeapShared::_roots_narrow;
OopHandle HeapShared::_roots;

#ifdef ASSERT
bool HeapShared::is_archived_object_during_dumptime(oop p) {
assert(HeapShared::is_heap_object_archiving_allowed(), "must be");
assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
return Universe::heap()->is_archived_object(p);
}
#endif

////////////////////////////////////////////////////////////////
//
// Java heap object archiving support
@@ -873,7 +881,7 @@ class WalkOopAndArchiveClosure: public BasicOopIterateClosure {
template <class T> void do_oop_work(T *p) {
oop obj = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(obj)) {
assert(!HeapShared::is_archived_object(obj),
assert(!HeapShared::is_archived_object_during_dumptime(obj),
"original objects must not point to archived objects");

size_t field_delta = pointer_delta(p, _orig_referencing_obj, sizeof(char));
@@ -892,7 +900,7 @@ class WalkOopAndArchiveClosure: public BasicOopIterateClosure {
oop archived = HeapShared::archive_reachable_objects_from(
_level + 1, _subgraph_info, obj, _is_closed_archive);
assert(archived != NULL, "VM should have exited with unarchivable objects for _level > 1");
assert(HeapShared::is_archived_object(archived), "must be");
assert(HeapShared::is_archived_object_during_dumptime(archived), "must be");

if (!_record_klasses_only) {
// Update the reference in the archived copy of the referencing object.
@@ -948,7 +956,7 @@ oop HeapShared::archive_reachable_objects_from(int level,
oop orig_obj,
bool is_closed_archive) {
assert(orig_obj != NULL, "must be");
assert(!is_archived_object(orig_obj), "sanity");
assert(!is_archived_object_during_dumptime(orig_obj), "sanity");

if (!JavaClasses::is_supported_for_archiving(orig_obj)) {
// This object has injected fields that cannot be supported easily, so we disallow them for now.
@@ -1166,10 +1174,10 @@ void HeapShared::verify_reachable_objects_from(oop obj, bool is_archived) {
set_has_been_seen_during_subgraph_recording(obj);

if (is_archived) {
assert(is_archived_object(obj), "must be");
assert(is_archived_object_during_dumptime(obj), "must be");
assert(find_archived_heap_object(obj) == NULL, "must be");
} else {
assert(!is_archived_object(obj), "must be");
assert(!is_archived_object_during_dumptime(obj), "must be");
assert(find_archived_heap_object(obj) != NULL, "must be");
}

@@ -376,7 +376,7 @@ class HeapShared: AllStatic {

static void fixup_mapped_regions() NOT_CDS_JAVA_HEAP_RETURN;

inline static bool is_archived_object(oop p) NOT_CDS_JAVA_HEAP_RETURN_(false);
static bool is_archived_object_during_dumptime(oop p) NOT_CDS_JAVA_HEAP_RETURN_(false);

static void resolve_classes(JavaThread* THREAD) NOT_CDS_JAVA_HEAP_RETURN;
static void initialize_from_archived_subgraph(Klass* k, JavaThread* THREAD) NOT_CDS_JAVA_HEAP_RETURN;
@@ -26,17 +26,11 @@
#define SHARE_CDS_HEAPSHARED_INLINE_HPP

#include "cds/heapShared.hpp"

#include "gc/shared/collectedHeap.inline.hpp"
#include "oops/compressedOops.inline.hpp"
#include "utilities/align.hpp"

#if INCLUDE_CDS_JAVA_HEAP

bool HeapShared::is_archived_object(oop p) {
return Universe::heap()->is_archived_object(p);
}

inline oop HeapShared::decode_from_archive(narrowOop v) {
assert(!CompressedOops::is_null(v), "narrow oop value can never be zero");
oop result = cast_to_oop((uintptr_t)_narrow_oop_base + ((uintptr_t)v << _narrow_oop_shift));
@@ -40,6 +40,7 @@
#include "code/debugInfo.hpp"
#include "code/dependencyContext.hpp"
#include "code/pcDesc.hpp"
#include "gc/shared/collectedHeap.inline.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/linkResolver.hpp"
#include "logging/log.hpp"
@@ -816,14 +817,11 @@ static void initialize_static_string_field(fieldDescriptor* fd, Handle mirror, T
static void initialize_static_string_field_for_dump(fieldDescriptor* fd, Handle mirror) {
DEBUG_ONLY(assert_valid_static_string_field(fd);)
assert(DumpSharedSpaces, "must be");
if (HeapShared::is_archived_object(mirror())) {
// Archive the String field and update the pointer.
oop s = mirror()->obj_field(fd->offset());
oop archived_s = StringTable::create_archived_string(s);
mirror()->obj_field_put(fd->offset(), archived_s);
} else {
guarantee(false, "Unexpected");
}
assert(HeapShared::is_archived_object_during_dumptime(mirror()), "must be");
// Archive the String field and update the pointer.
oop s = mirror()->obj_field(fd->offset());
oop archived_s = StringTable::create_archived_string(s);
mirror()->obj_field_put(fd->offset(), archived_s);
}
#endif

@@ -1342,7 +1340,7 @@ bool java_lang_Class::restore_archived_mirror(Klass *k,

// mirror is archived, restore
log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));
assert(HeapShared::is_archived_object(m), "must be archived mirror object");
assert(Universe::heap()->is_archived_object(m), "must be archived mirror object");
assert(as_Klass(m) == k, "must be");
Handle mirror(THREAD, m);

@@ -720,7 +720,7 @@ oop StringTable::lookup_shared(const jchar* name, int len) {
oop StringTable::create_archived_string(oop s) {
assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
assert(java_lang_String::is_instance(s), "sanity");
assert(!HeapShared::is_archived_object(s), "sanity");
assert(!HeapShared::is_archived_object_during_dumptime(s), "sanity");

oop new_s = NULL;
typeArrayOop v = java_lang_String::value_no_keepalive(s);
@@ -23,9 +23,10 @@
*/

#include "precompiled.hpp"
#include "cds/heapShared.inline.hpp"
#include "classfile/altHashing.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "gc/shared/collectedHeap.inline.hpp"
#include "gc/shared/gc_globals.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "oops/access.inline.hpp"
@@ -218,7 +219,7 @@ void oopDesc::release_double_field_put(int offset, jdouble value) { HeapAcce
#ifdef ASSERT
void oopDesc::verify_forwardee(oop forwardee) {
#if INCLUDE_CDS_JAVA_HEAP
assert(!HeapShared::is_archived_object(forwardee) && !HeapShared::is_archived_object(this),
assert(!Universe::heap()->is_archived_object(forwardee) && !Universe::heap()->is_archived_object(this),
"forwarding archive object");
#endif
}
@@ -1933,7 +1933,7 @@ WB_END

WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj))
oop obj_oop = JNIHandles::resolve(obj);
return HeapShared::is_archived_object(obj_oop);
return Universe::heap()->is_archived_object(obj_oop);
WB_END

WB_ENTRY(jboolean, WB_IsSharedClass(JNIEnv* env, jobject wb, jclass clazz))

1 comment on commit 024c402

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 024c402 Jul 21, 2021

Please sign in to comment.