< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/RewriteBytecodesTest.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /*
  26  * @test
  27  * @summary Use ClassLoader.defineClass() to load a class with rewritten bytecode. Make sure
  28  *          the archived class with the same name is not loaded.
  29  * @requires vm.cds
  30  * @library /test/lib
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  *          jdk.jartool/sun.tools.jar
  34  * @compile test-classes/RewriteBytecodes.java test-classes/Util.java test-classes/Super.java test-classes/Child.java
  35  * @build sun.hotspot.WhiteBox
  36  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  37  * @run driver RewriteBytecodesTest
  38  */
  39 
  40 import java.io.File;
  41 import jdk.test.lib.process.OutputAnalyzer;
  42 
  43 public class RewriteBytecodesTest {
  44   public static void main(String[] args) throws Exception {
  45     String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
  46     String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
  47 
  48     String appJar = JarBuilder.build("dynamic_define", "RewriteBytecodes", "Util", "Super", "Child");
  49     String superClsFile = (new File(System.getProperty("test.classes", "."), "Super.class")).getPath();
  50 
  51     TestCommon.dump(appJar, TestCommon.list("RewriteBytecodes", "Super", "Child"),
  52                     // command-line arguments ...
  53                     use_whitebox_jar);
  54 
  55     OutputAnalyzer output = TestCommon.exec(appJar,
  56                     // command-line arguments ...
  57                     "--add-opens=java.base/java.lang=ALL-UNNAMED",
  58                     use_whitebox_jar,
  59                     "-XX:+UnlockDiagnosticVMOptions",
  60                     "-XX:+WhiteBoxAPI",
  61                     "RewriteBytecodes", superClsFile);
  62     TestCommon.checkExec(output);
  63   }
  64 }


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /*
  26  * @test
  27  * @summary Use Lookup.defineClass() to load a class with rewritten bytecode. Make sure
  28  *          the archived class with the same name is not loaded.
  29  * @requires vm.cds
  30  * @library /test/lib
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  *          jdk.jartool/sun.tools.jar
  34  * @compile test-classes/RewriteBytecodes.java test-classes/Util.java test-classes/Super.java test-classes/Child.java
  35  * @build sun.hotspot.WhiteBox
  36  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  37  * @run driver RewriteBytecodesTest
  38  */
  39 
  40 import java.io.File;
  41 import jdk.test.lib.process.OutputAnalyzer;
  42 
  43 public class RewriteBytecodesTest {
  44   public static void main(String[] args) throws Exception {
  45     String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
  46     String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
  47 
  48     String appJar = JarBuilder.build("dynamic_define", "RewriteBytecodes", "Util", "Super", "Child");
  49     String superClsFile = (new File(System.getProperty("test.classes", "."), "Super.class")).getPath();
  50 
  51     TestCommon.dump(appJar, TestCommon.list("RewriteBytecodes", "Super", "Child"),
  52                     // command-line arguments ...
  53                     use_whitebox_jar);
  54 
  55     OutputAnalyzer output = TestCommon.exec(appJar,
  56                     // command-line arguments ...

  57                     use_whitebox_jar,
  58                     "-XX:+UnlockDiagnosticVMOptions",
  59                     "-XX:+WhiteBoxAPI",
  60                     "RewriteBytecodes", superClsFile);
  61     TestCommon.checkExec(output);
  62   }
  63 }
< prev index next >