Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/RedefineTests/RedefineRunningMethods.java
32284 views
/*1* Copyright (c) 2014, 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 805500826* @summary Redefine EMCP and non-EMCP methods that are running in an infinite loop27* @library /testlibrary28* @build RedefineClassHelper29* @run main RedefineClassHelper30* @run main/othervm -javaagent:redefineagent.jar RedefineRunningMethods31*/32public class RedefineRunningMethods {3334public static String newB =35"class RedefineRunningMethods$B {" +36" static int count1 = 0;" +37" static int count2 = 0;" +38" public static volatile boolean stop = false;" +39" static void localSleep() { " +40" try{ " +41" Thread.currentThread().sleep(10);" +42" } catch(InterruptedException ie) { " +43" } " +44" } " +45" public static void infinite() { " +46" System.out.println(\"infinite called\");" +47" }" +48" public static void infinite_emcp() { " +49" while (!stop) { count2++; localSleep(); }" +50" }" +51"}";5253public static String evenNewerB =54"class RedefineRunningMethods$B {" +55" static int count1 = 0;" +56" static int count2 = 0;" +57" public static volatile boolean stop = false;" +58" static void localSleep() { " +59" try{ " +60" Thread.currentThread().sleep(1);" +61" } catch(InterruptedException ie) { " +62" } " +63" } " +64" public static void infinite() { }" +65" public static void infinite_emcp() { " +66" System.out.println(\"infinite_emcp now obsolete called\");" +67" }" +68"}";6970static class B {71static int count1 = 0;72static int count2 = 0;73public static volatile boolean stop = false;74static void localSleep() {75try{76Thread.currentThread().sleep(10);//sleep for 10 ms77} catch(InterruptedException ie) {78}79}8081public static void infinite() {82while (!stop) { count1++; localSleep(); }83}84public static void infinite_emcp() {85while (!stop) { count2++; localSleep(); }86}87}888990public static void main(String[] args) throws Exception {9192new Thread() {93public void run() {94B.infinite();95}96}.start();9798new Thread() {99public void run() {100B.infinite_emcp();101}102}.start();103104RedefineClassHelper.redefineClass(B.class, newB);105106System.gc();107108B.infinite();109110// Start a thread with the second version of infinite_emcp running111new Thread() {112public void run() {113B.infinite_emcp();114}115}.start();116117for (int i = 0; i < 20 ; i++) {118String s = new String("some garbage");119System.gc();120}121122RedefineClassHelper.redefineClass(B.class, evenNewerB);123System.gc();124125for (int i = 0; i < 20 ; i++) {126B.infinite();127String s = new String("some garbage");128System.gc();129}130131B.infinite_emcp();132133// purge should clean everything up.134B.stop = true;135136for (int i = 0; i < 20 ; i++) {137B.infinite();138String s = new String("some garbage");139System.gc();140}141}142}143144145