New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8276126: Dump time class transformation causes heap objects of non-boot classes to be archived #6484
Closed
calvinccheung
wants to merge
4
commits into
openjdk:master
from
calvinccheung:8276126-dump-time-class-transform-heap-objects
+201
−10
Closed
8276126: Dump time class transformation causes heap objects of non-boot classes to be archived #6484
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c033dd4
8276126: Dump time class transformation causes heap objects of non-bo…
calvinccheung 58b1d9f
Fix the condition check in ClassLoaderExt::record_result().
calvinccheung 381f26d
Simplify the fix by passing a 'redefined' flag from KlassFactory::cre…
calvinccheung f3eee00
remove the unused stream parameter in ClassLoaderExt::record_result()
calvinccheung File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2021, 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 | ||
* 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 8276126 | ||
* @summary Test static dumping with java agent transforming a class loaded | ||
* by the boot class loader. | ||
* @requires vm.cds.write.archived.java.heap | ||
* @requires vm.jvmti | ||
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes | ||
* @compile test-classes/Hello.java | ||
* @compile test-classes/TransformBootClass.java | ||
* @run driver LambdaWithJavaAgent | ||
*/ | ||
|
||
import jdk.test.lib.cds.CDSOptions; | ||
import jdk.test.lib.cds.CDSTestUtils; | ||
import jdk.test.lib.process.OutputAnalyzer; | ||
import jdk.test.lib.process.ProcessTools; | ||
import jdk.test.lib.helpers.ClassFileInstaller; | ||
|
||
public class LambdaWithJavaAgent { | ||
|
||
public static String agentClasses[] = { | ||
TransformBootClass.class.getName(), | ||
}; | ||
|
||
public static void main(String[] args) throws Exception { | ||
String mainClass = Hello.class.getName(); | ||
String namePrefix = "lambda-with-java-agent"; | ||
JarBuilder.build(namePrefix, mainClass); | ||
|
||
String appJar = TestCommon.getTestJar(namePrefix + ".jar"); | ||
String classList = namePrefix + ".list"; | ||
String archiveName = namePrefix + ".jsa"; | ||
|
||
String agentJar = | ||
ClassFileInstaller.writeJar("TransformBootClass.jar", | ||
ClassFileInstaller.Manifest.fromSourceFile("test-classes/TransformBootClass.mf"), | ||
agentClasses); | ||
String useJavaAgent = "-javaagent:" + agentJar + "=jdk/internal/math/FDBigInteger"; | ||
|
||
// dump class list | ||
CDSTestUtils.dumpClassList(classList, "-cp", appJar, mainClass); | ||
|
||
// create archive with the class list | ||
CDSOptions opts = (new CDSOptions()) | ||
.addPrefix("-XX:ExtraSharedClassListFile=" + classList, | ||
"-cp", appJar, | ||
"-XX:+AllowArchivingWithJavaAgent", | ||
useJavaAgent, | ||
"-Xlog:class+load,cds+class=debug,cds") | ||
.setArchiveName(archiveName); | ||
OutputAnalyzer output = CDSTestUtils.createArchiveAndCheck(opts); | ||
output.shouldContain("CDS heap objects cannot be written because class jdk.internal.math.FDBigInteger maybe modified by ClassFileLoadHook") | ||
.shouldContain("Skipping jdk/internal/math/FDBigInteger: Unsupported location") | ||
.shouldMatch(".class.load.*jdk.internal.math.FDBigInteger.*source.*modules"); | ||
|
||
// run with archive | ||
CDSOptions runOpts = (new CDSOptions()) | ||
.addPrefix("-cp", appJar, "-Xlog:class+load,cds=debug", | ||
"-XX:+AllowArchivingWithJavaAgent", | ||
useJavaAgent) | ||
.setArchiveName(archiveName) | ||
.setUseVersion(false) | ||
.addSuffix(mainClass); | ||
output = CDSTestUtils.runWithArchive(runOpts); | ||
TestCommon.checkExecReturn(output, 0, true, | ||
"Hello source: shared objects file"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2021, 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 | ||
* 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. | ||
* | ||
*/ | ||
|
||
import java.lang.instrument.ClassFileTransformer; | ||
import java.lang.instrument.Instrumentation; | ||
import java.lang.instrument.IllegalClassFormatException; | ||
import java.security.ProtectionDomain; | ||
|
||
public class TransformBootClass implements ClassFileTransformer { | ||
|
||
static String targetClass = null; | ||
|
||
public byte[] transform(ClassLoader loader, String name, Class<?> classBeingRedefined, | ||
ProtectionDomain pd, byte[] buffer) throws IllegalClassFormatException { | ||
|
||
if (name.equals(targetClass)) { | ||
System.out.println("Transforming class " + name); | ||
return buffer; | ||
} | ||
return null; | ||
} | ||
|
||
private static Instrumentation savedInstrumentation; | ||
|
||
public static void premain(String agentArguments, Instrumentation instrumentation) { | ||
System.out.println("TransformBootClass.premain() is called"); | ||
instrumentation.addTransformer(new TransformBootClass(), /*canRetransform=*/true); | ||
savedInstrumentation = instrumentation; | ||
if (agentArguments != null) { | ||
targetClass = agentArguments; | ||
} | ||
} | ||
|
||
public static Instrumentation getInstrumentation() { | ||
return savedInstrumentation; | ||
} | ||
|
||
public static void agentmain(String args, Instrumentation inst) throws Exception { | ||
premain(args, inst); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Manifest-Version: 1.0 | ||
Premain-Class: TransformBootClass | ||
Agent-Class: TransformBootClass | ||
Can-Retransform-Classes: true | ||
Can-Redefine-Classes: true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function is call during dump time (the assert at first line of this function check that) so DumpSharedSpace can be removed.
I am a little confused by this part: If 'redefined' is 'true', The 'redefined' only should be enough for set disable_writing() whether other conditions stands or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Arguments::assert_is_dumping_archive()
includes both static and dynamic dumping. The archiving of heap objects is performed only during static dumping. So the check forDumpShareSpaces
is needed.The
redefined
flag alone is not enough to disable writing heap objects to archive. If a class loaded by an AppClassLoader and is redefined, it should not disable archiving heap objects. We currently have some test cases under runtime/cds/appcds/javaldr to test that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.