Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/RedefineClasses/redefinecls001a.java
41161 views
/*1* Copyright (c) 2001, 2018, 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// THIS TEST IS LINE NUMBER SENSITIVE2425package nsk.jdwp.VirtualMachine.RedefineClasses;2627import nsk.share.*;28import nsk.share.jpda.*;29import nsk.share.jdwp.*;3031import java.io.*;3233/**34* This class represents debuggee part in the test.35*/36public class redefinecls001a {3738// line nunber for breakpoint39public static final int BREAKPOINT_LINE_BEFORE = 76;40public static final int BREAKPOINT_LINE_AFTER = 86;4142// fields for methods redefinition results43// public static Integer constructorInvoked = Integer(redefinecls001.METHOD_NOT_INVOKED);44// public static Integer staticMethodInvoked = Integer(redefinecls001.METHOD_NOT_INVOKED);45// public static Integer objectMethodInvoked = Integer(redefinecls001.METHOD_NOT_INVOKED);4647// scaffold objects48static volatile ArgumentHandler argumentHandler = null;49static volatile Log log = null;5051public static void main(String args[]) {52System.exit(redefinecls001.JCK_STATUS_BASE + redefinecls001a.runIt(args, System.err));53}5455public static int runIt(String args[], PrintStream out) {56//make log for debugee messages57argumentHandler = new ArgumentHandler(args);58log = new Log(out, argumentHandler);5960// create tested thread61log.display("Creating object of tested class");62redefinecls001b.staticField = redefinecls001b.FINAL_FIELD_VALUE;63redefinecls001b.log = log;64redefinecls001b object = new redefinecls001b(redefinecls001b.FINAL_FIELD_VALUE);65log.display(" ... object created");6667// invoke tested method before redefinition68log.display("Invoking tested methods before redefinition");69redefinecls001b.testedStaticMethod();70object.testedObjectMethod();71printInvocationResult();7273log.display("\nBreakpoint line before redefinition reached");74// next line is for breakpoint before redefinition75int foo = 0; // BREAKPOINT_LINE_BEFORE7677// invoke tested method after redefinition78log.display("Invoking tested methods after redefinition");79redefinecls001b.testedStaticMethod();80object.testedObjectMethod();81printInvocationResult();8283log.display("\nBreakpoint line after redefinition reached");84// next line is for breakpoint after redefinition85foo = 1; // BREAKPOINT_LINE_AFTER8687log.display("Debugee PASSED");88return redefinecls001.PASSED;89}9091// print information about kind of invoked methods92private static void printInvocationResult() {93log.display("Result of methods invokation:");94log.display(" constructorInvoked: " + methodKind(redefinecls001b.constructorInvoked));95log.display(" staticMethodInvoked: " + methodKind(redefinecls001b.staticMethodInvoked));96log.display(" objectMethodInvoked: " + methodKind(redefinecls001b.objectMethodInvoked));97}9899// return string representation of kind of invoked method100private static String methodKind(int kind) {101switch (kind) {102case redefinecls001b.METHOD_NOT_INVOKED:103return "METHOD_NOT_INVOKED";104case redefinecls001b.REDEFINED_METHOD_INVOKED:105return "REDEFINED_METHOD_INVOKED";106case redefinecls001b.NOT_REDEFINED_METHOD_INVOKED:107return "NOT_REDEFINED_METHOD_INVOKED";108default:109return "UNKNOWN_METHOD_KIND";110}111}112}113114115