Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineRunningMethods.java
41153 views
/*1* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8055008 8197901 801031926* @summary Redefine EMCP and non-EMCP methods that are running in an infinite loop27* @requires vm.jvmti28* @library /test/lib29* @modules java.base/jdk.internal.misc30* @modules java.compiler31* java.instrument32* jdk.jartool/sun.tools.jar33* @run main RedefineClassHelper34* @run main/othervm/timeout=180 -javaagent:redefineagent.jar -Xlog:redefine+class+iklass+add=trace,redefine+class+iklass+purge=trace,class+loader+data=debug,safepoint+cleanup,gc+phases=debug:rt.log RedefineRunningMethods35*/363738// package access top-level class to avoid problem with RedefineClassHelper39// and nested types.40class RedefineRunningMethods_B {41static int count1 = 0;42static int count2 = 0;43public static volatile boolean stop = false;44static void localSleep() {45try{46Thread.currentThread().sleep(10);//sleep for 10 ms47} catch(InterruptedException ie) {48}49}5051public static void infinite() {52while (!stop) { count1++; localSleep(); }53}54public static void infinite_emcp() {55while (!stop) { count2++; localSleep(); }56}57}5859public class RedefineRunningMethods {6061public static String newB =62"class RedefineRunningMethods_B {" +63" static int count1 = 0;" +64" static int count2 = 0;" +65" public static volatile boolean stop = false;" +66" static void localSleep() { " +67" try{ " +68" Thread.currentThread().sleep(10);" +69" } catch(InterruptedException ie) { " +70" } " +71" } " +72" public static void infinite() { " +73" System.out.println(\"infinite called\");" +74" }" +75" public static void infinite_emcp() { " +76" while (!stop) { count2++; localSleep(); }" +77" }" +78"}";7980public static String evenNewerB =81"class RedefineRunningMethods_B {" +82" static int count1 = 0;" +83" static int count2 = 0;" +84" public static volatile boolean stop = false;" +85" static void localSleep() { " +86" try{ " +87" Thread.currentThread().sleep(1);" +88" } catch(InterruptedException ie) { " +89" } " +90" } " +91" public static void infinite() { }" +92" public static void infinite_emcp() { " +93" System.out.println(\"infinite_emcp now obsolete called\");" +94" }" +95"}";969798public static void main(String[] args) throws Exception {99100new Thread() {101public void run() {102RedefineRunningMethods_B.infinite();103}104}.start();105106new Thread() {107public void run() {108RedefineRunningMethods_B.infinite_emcp();109}110}.start();111112RedefineClassHelper.redefineClass(RedefineRunningMethods_B.class, newB);113114System.gc();115116RedefineRunningMethods_B.infinite();117118// Start a thread with the second version of infinite_emcp running119new Thread() {120public void run() {121RedefineRunningMethods_B.infinite_emcp();122}123}.start();124125for (int i = 0; i < 20 ; i++) {126String s = new String("some garbage");127System.gc();128}129130RedefineClassHelper.redefineClass(RedefineRunningMethods_B.class, evenNewerB);131System.gc();132133for (int i = 0; i < 20 ; i++) {134RedefineRunningMethods_B.infinite();135String s = new String("some garbage");136System.gc();137}138139RedefineRunningMethods_B.infinite_emcp();140141// purge should clean everything up.142RedefineRunningMethods_B.stop = true;143144for (int i = 0; i < 20 ; i++) {145RedefineRunningMethods_B.infinite();146String s = new String("some garbage");147System.gc();148}149}150}151152153