< prev index next >

test/hotspot/jtreg/runtime/appcds/redefineClass/RedefineBasic.java

Print this page
rev 50289 : [mq]: jep181-rev5

*** 1,7 **** /* ! * Copyright (c) 2016, 2017, 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. --- 1,7 ---- /* ! * Copyright (c) 2016, 2018, 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.
*** 22,60 **** * */ import sun.hotspot.WhiteBox; public class RedefineBasic { public static String newB = ! " class RedefineBasic$B { " + " public static void okToCallBeforeRedefine() { " + " throw new RuntimeException(\"newB: okToCallBeforeRedefine is " + " called after redefinition, test failed\"); }" + " public static void okToCallAfterRedefine() { " + " System.out.println(\"newB: okToCallAfterRedefine\"); } " + " } "; - static class B { - public static void okToCallBeforeRedefine() { - System.out.println("okToCallBeforeRedefine"); - } - public static void okToCallAfterRedefine() { - throw new RuntimeException( - "okToCallAfterRedefine is called before redefinition, test failed"); - } - } ! static class SubclassOfB extends B { public static void testAfterRedefine() { ! B.okToCallAfterRedefine(); } } ! class Subclass2OfB extends B { public void testAfterRedefine() { super.okToCallAfterRedefine(); } } --- 22,62 ---- * */ import sun.hotspot.WhiteBox; + // package access top-level class to avoid problem with RedefineClassHelper + // and nested types. + class RedefineBasic_B { + public static void okToCallBeforeRedefine() { + System.out.println("okToCallBeforeRedefine"); + } + public static void okToCallAfterRedefine() { + throw new RuntimeException("okToCallAfterRedefine is called before redefinition, test failed"); + } + } + public class RedefineBasic { public static String newB = ! " class RedefineBasic_B { " + " public static void okToCallBeforeRedefine() { " + " throw new RuntimeException(\"newB: okToCallBeforeRedefine is " + " called after redefinition, test failed\"); }" + " public static void okToCallAfterRedefine() { " + " System.out.println(\"newB: okToCallAfterRedefine\"); } " + " } "; ! static class SubclassOfB extends RedefineBasic_B { public static void testAfterRedefine() { ! RedefineBasic_B.okToCallAfterRedefine(); } } ! class Subclass2OfB extends RedefineBasic_B { public void testAfterRedefine() { super.okToCallAfterRedefine(); } }
*** 72,92 **** public static void main(String[] args) throws Exception { WhiteBox wb = WhiteBox.getWhiteBox(); verifyClassIsShared(wb, RedefineBasic.class); ! verifyClassIsShared(wb, B.class); verifyClassIsShared(wb, SubclassOfB.class); verifyClassIsShared(wb, Subclass2OfB.class); // (1) Test case: verify that original B works as expected // and that redefined B is shared and works as expected, // with new behavior ! B.okToCallBeforeRedefine(); ! RedefineClassHelper.redefineClass(B.class, newB); ! verifyClassIsShared(wb, B.class); ! B.okToCallAfterRedefine(); // Static subclass of the super: // 1. Make sure it is still shared // 2. and it calls the correct super (the redefined one) verifyClassIsShared(wb, SubclassOfB.class); --- 74,94 ---- public static void main(String[] args) throws Exception { WhiteBox wb = WhiteBox.getWhiteBox(); verifyClassIsShared(wb, RedefineBasic.class); ! verifyClassIsShared(wb, RedefineBasic_B.class); verifyClassIsShared(wb, SubclassOfB.class); verifyClassIsShared(wb, Subclass2OfB.class); // (1) Test case: verify that original B works as expected // and that redefined B is shared and works as expected, // with new behavior ! RedefineBasic_B.okToCallBeforeRedefine(); ! RedefineClassHelper.redefineClass(RedefineBasic_B.class, newB); ! verifyClassIsShared(wb, RedefineBasic_B.class); ! RedefineBasic_B.okToCallAfterRedefine(); // Static subclass of the super: // 1. Make sure it is still shared // 2. and it calls the correct super (the redefined one) verifyClassIsShared(wb, SubclassOfB.class);
< prev index next >