Skip to content
Permalink
Browse files
8286066: assert(k != __null) failed: klass not loaded caused by Fille…
…rObject_klass

Reviewed-by: dholmes, tschatzl, iklam
  • Loading branch information
DamonFool committed May 5, 2022
1 parent 6a1b145 commit 7ebc4bce930e7d406f1e68c8bd09ac1dc3a21e5a
Showing 4 changed files with 72 additions and 4 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, 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
@@ -30,6 +30,7 @@
#include "classfile/systemDictionary.hpp"
#include "classfile/vmClasses.hpp"
#include "classfile/vmSymbols.hpp"
#include "gc/shared/collectedHeap.hpp"
#include "memory/metaspaceClosure.hpp"
#include "memory/universe.hpp"
#include "oops/instanceKlass.hpp"
@@ -122,10 +123,10 @@ void vmClasses::resolve_all(TRAPS) {
// Preload commonly used klasses
vmClassID scan = vmClassID::FIRST;
// first do Object, then String, Class
resolve_through(VM_CLASS_ID(Object_klass), scan, CHECK);
CollectedHeap::set_filler_object_klass(vmClasses::Object_klass());
#if INCLUDE_CDS
if (UseSharedSpaces) {
resolve_through(VM_CLASS_ID(Object_klass), scan, CHECK);

// It's unsafe to access the archived heap regions before they
// are fixed up, so we must do the fixup as early as possible
// before the archived java objects are accessed by functions
@@ -191,6 +192,8 @@ void vmClasses::resolve_all(TRAPS) {
resolve_through(jsr292_group_end, scan, CHECK);
resolve_until(vmClassID::LIMIT, scan, CHECK);

CollectedHeap::set_filler_object_klass(vmClasses::FillerObject_klass());

_box_klasses[T_BOOLEAN] = vmClasses::Boolean_klass();
_box_klasses[T_CHAR] = vmClasses::Character_klass();
_box_klasses[T_FLOAT] = vmClasses::Float_klass();
@@ -60,6 +60,7 @@

class ClassLoaderData;

Klass* CollectedHeap::_filler_object_klass = NULL;
size_t CollectedHeap::_filler_array_max_size = 0;

class GCMessage : public FormatBuffer<1024> {
@@ -467,7 +468,7 @@ CollectedHeap::fill_with_object_impl(HeapWord* start, size_t words, bool zap)
fill_with_array(start, words, zap);
} else if (words > 0) {
assert(words == min_fill_size(), "unaligned size");
ObjAllocator allocator(vmClasses::FillerObject_klass(), words);
ObjAllocator allocator(CollectedHeap::filler_object_klass(), words);
allocator.initialize(start);
}
}
@@ -104,6 +104,10 @@ class CollectedHeap : public CHeapObj<mtGC> {
size_t _capacity_at_last_gc;
size_t _used_at_last_gc;

// First, set it to java_lang_Object.
// Then, set it to FillerObject after the FillerObject_klass loading is complete.
static Klass* _filler_object_klass;

protected:
// Not used by all GCs
MemRegion _reserved;
@@ -204,6 +208,14 @@ class CollectedHeap : public CHeapObj<mtGC> {
return _filler_array_max_size;
}

static inline Klass* filler_object_klass() {
return _filler_object_klass;
}

static inline void set_filler_object_klass(Klass* k) {
_filler_object_klass = k;
}

virtual Name kind() const = 0;

virtual const char* name() const = 0;
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2022 THL A29 Limited, a Tencent company. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* bug 8286066
* @summary VM crash caused by unloaded FillerObject_klass
* @library /test/lib
* @requires vm.cds
* @run driver FillerObjectLoadTest
*/

import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

public class FillerObjectLoadTest {
public static void main(String... args) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-XX:+IgnoreUnrecognizedVMOptions", "-XX:-UseCompressedClassPointers",
"-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", "-Xshare:dump",
"-XX:SharedArchiveFile=" + TestCommon.getNewArchiveName());
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
analyzer.shouldHaveExitValue(0);

pb = ProcessTools.createJavaProcessBuilder(
"-XX:+IgnoreUnrecognizedVMOptions", "-XX:-UseCompressedClassPointers",
"-XX:TLABSize=2048", "-Xshare:dump",
"-XX:SharedArchiveFile=" + TestCommon.getNewArchiveName());
analyzer = new OutputAnalyzer(pb.start());
analyzer.shouldHaveExitValue(0);
}
}

1 comment on commit 7ebc4bc

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 7ebc4bc May 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.