This commit is contained in:
David Holmes 2022-08-03 08:11:10 +00:00
commit 0971d34646
6 changed files with 24 additions and 27 deletions

View File

@ -122,26 +122,22 @@ import sun.security.util.SecurityConstants;
* in this class causes a {@link NullPointerException NullPointerException} to
* be thrown. </p>
*
* <h2> Example usage: </h2>
* <h2> Example </h2>
*
* <p> This example creates a configuration by resolving a module named
* "{@code myapp}" with the configuration for the boot layer as the parent. It
* then creates a new layer with the modules in this configuration. All modules
* are defined to the same class loader. </p>
*
* <pre>{@code
* {@snippet :
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
*
* ModuleLayer parent = ModuleLayer.boot();
*
* Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp"));
*
* Configuration cf = parent.configuration()
* .resolve(finder, ModuleFinder.of(), Set.of("myapp"));
* ClassLoader scl = ClassLoader.getSystemClassLoader();
*
* ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
*
* Class<?> c = layer.findLoader("myapp").loadClass("app.Main");
* }</pre>
* }
*
* @since 9
* @see Module#getLayer()

View File

@ -83,11 +83,10 @@ import jdk.internal.vm.annotation.Stable;
* parent configuration. It prints the name of each resolved module and the
* names of the modules that each module reads. </p>
*
* <pre>{@code
* {@snippet :
* Path dir1 = ..., dir2 = ..., dir3 = ...;
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
*
* Configuration parent = ModuleLayer.boot().configuration();
*
* Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp"));
* cf.modules().forEach(m -> {
* System.out.format("%s -> %s%n",
@ -96,7 +95,7 @@ import jdk.internal.vm.annotation.Stable;
* .map(ResolvedModule::name)
* .collect(Collectors.joining(", ")));
* });
* }</pre>
* }
*
* @since 9
* @see java.lang.ModuleLayer

View File

@ -1545,13 +1545,14 @@ public class ModuleDescriptor
* <cite>The Java Language Specification</cite>. </p>
*
* <p> Example usage: </p>
* <pre>{@code ModuleDescriptor descriptor = ModuleDescriptor.newModule("stats.core")
* {@snippet :
* ModuleDescriptor descriptor = ModuleDescriptor.newModule("stats.core")
* .requires("java.base")
* .exports("org.acme.stats.core.clustering")
* .exports("org.acme.stats.core.regression")
* .packages(Set.of("org.acme.stats.core.internal"))
* .build();
* }</pre>
* }
*
* @apiNote A {@code Builder} checks the components and invariants as
* components are added to the builder. The rationale for this is to detect

View File

@ -54,15 +54,12 @@ import jdk.internal.module.SystemModuleFinders;
*
* <p> Example usage: </p>
*
* <pre>{@code
* Path dir1, dir2, dir3;
*
* {@snippet :
* Path dir1 = ..., dir2 = ..., dir3 = ...;
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
*
* Optional<ModuleReference> omref = finder.find("jdk.foo");
* omref.ifPresent(mref -> ... );
*
* }</pre>
* }
*
* <p> The {@link #find(String) find} and {@link #findAll() findAll} methods
* defined here can fail for several reasons. These include I/O errors, errors

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 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
@ -56,9 +56,11 @@ public class TestClassLoaderStatsEvent {
private final static String CLASS_LOADER_NAME = "MyDummyClassLoader";
private final static String CLASSLOADER_TYPE_NAME = "jdk.jfr.event.runtime.TestClassLoaderStatsEvent$DummyClassLoader";
public static DummyClassLoader dummyloader;
public static Class<?>[] classes;
public static void main(String[] args) throws Throwable {
createDummyClassLoader(CLASS_LOADER_NAME);
System.gc();
Recording recording = new Recording();
recording.enable(EVENT_NAME);
@ -106,7 +108,7 @@ public class TestClassLoaderStatsEvent {
Method m = c.getDeclaredMethod("createNonFindableClasses", byte[].class);
m.setAccessible(true);
m.invoke(null, klassbuf);
classes = (Class[]) m.invoke(null, klassbuf);
}
public static class DummyClassLoader extends ClassLoader {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 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
@ -85,10 +85,12 @@ class TestClass {
r.run();
}
public static void createNonFindableClasses(byte[] klassbuf) throws Throwable {
public static Class<?>[] createNonFindableClasses(byte[] klassbuf) throws Throwable {
// Create a hidden class and an array of hidden classes.
Lookup lookup = MethodHandles.lookup();
Class<?> clh = lookup.defineHiddenClass(klassbuf, false, NESTMATE).lookupClass();
Class<?> arrayOfHidden = Array.newInstance(clh, 10).getClass(); // HAS ISSUES?
Class<?>[] classes = new Class[2];
classes[0] = lookup.defineHiddenClass(klassbuf, false, NESTMATE).lookupClass();
classes[1] = Array.newInstance(classes[0], 10).getClass(); // HAS ISSUES?
return classes;
}
}