Skip to content
Permalink
Browse files
8284556: Ensure reachability of classes in runtime/whitebox/TestHidde…
…nClassIsAlive.java and serviceability/dcmd/vm/ClassLoaderHierarchyTest.java

Reviewed-by: cjplummer
  • Loading branch information
lmesnik committed Apr 8, 2022
1 parent 662320a commit a8c87526027bed750e3dcab78139b49bc0a05f83
Showing 2 changed files with 9 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
@@ -38,6 +38,7 @@
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.ref.Reference;

import sun.hotspot.WhiteBox;

@@ -48,14 +49,14 @@ final class MyClass {

public class TestHiddenClassIsAlive {


public static void main(String[] args) throws Throwable {
byte[] classBytes = readClassFile("MyClass.class");
Lookup lookup = MethodHandles.lookup();
Class<?> c = lookup.defineHiddenClass(classBytes, true).lookupClass();
if (!WhiteBox.getWhiteBox().isClassAlive("MyClass")) {
throw new RuntimeException("Hidden class should be alive");
}
Reference.reachabilityFence(c);
}

static byte[] readClassFile(String classFileName) throws Exception {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -44,6 +44,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.lang.ref.Reference;

public class ClassLoaderHierarchyTest {

@@ -93,6 +94,10 @@ public void run(CommandExecutor executor) throws ClassNotFoundException {
output.shouldMatch("Bill.*TestClassLoader");
output.shouldContain("TestClass2");
output.shouldContain("Hidden Classes:");

Reference.reachabilityFence(unnamed_cl);
Reference.reachabilityFence(named_cl);
Reference.reachabilityFence(named_child_cl);
}

static class TestClassLoader extends ClassLoader {
@@ -163,4 +168,3 @@ class TestClass2 {
r.run();
}
}

1 comment on commit a8c8752

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on a8c8752 Apr 8, 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.