test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/RedefineClasses/redefinecls001a.java
changeset 50317 cf71bff5f533
equal deleted inserted replaced
50316:60ebcc705421 50317:cf71bff5f533
       
     1 /*
       
     2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     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 //    THIS TEST IS LINE NUMBER SENSITIVE
       
    25 
       
    26 package nsk.jdwp.VirtualMachine.RedefineClasses;
       
    27 
       
    28 import nsk.share.*;
       
    29 import nsk.share.jpda.*;
       
    30 import nsk.share.jdwp.*;
       
    31 
       
    32 import java.io.*;
       
    33 
       
    34 /**
       
    35  * This class represents debuggee part in the test.
       
    36  */
       
    37 public class redefinecls001a {
       
    38 
       
    39     // line nunber for breakpoint
       
    40     public static final int BREAKPOINT_LINE_BEFORE = 76;
       
    41     public static final int BREAKPOINT_LINE_AFTER = 86;
       
    42 
       
    43     // fields for methods redefinition results
       
    44 //    public static Integer constructorInvoked = Integer(redefinecls001.METHOD_NOT_INVOKED);
       
    45 //    public static Integer staticMethodInvoked = Integer(redefinecls001.METHOD_NOT_INVOKED);
       
    46 //    public static Integer objectMethodInvoked = Integer(redefinecls001.METHOD_NOT_INVOKED);
       
    47 
       
    48     // scaffold objects
       
    49     static volatile ArgumentHandler argumentHandler = null;
       
    50     static volatile Log log = null;
       
    51 
       
    52     public static void main(String args[]) {
       
    53         System.exit(redefinecls001.JCK_STATUS_BASE + redefinecls001a.runIt(args, System.err));
       
    54     }
       
    55 
       
    56     public static int runIt(String args[], PrintStream out) {
       
    57         //make log for debugee messages
       
    58         argumentHandler = new ArgumentHandler(args);
       
    59         log = new Log(out, argumentHandler);
       
    60 
       
    61         // create tested thread
       
    62         log.display("Creating object of tested class");
       
    63         redefinecls001b.staticField = redefinecls001b.FINAL_FIELD_VALUE;
       
    64         redefinecls001b.log = log;
       
    65         redefinecls001b object = new redefinecls001b(redefinecls001b.FINAL_FIELD_VALUE);
       
    66         log.display("  ... object created");
       
    67 
       
    68         // invoke tested method before redefinition
       
    69         log.display("Invoking tested methods before redefinition");
       
    70         redefinecls001b.testedStaticMethod();
       
    71         object.testedObjectMethod();
       
    72         printInvocationResult();
       
    73 
       
    74         log.display("\nBreakpoint line before redefinition reached");
       
    75         // next line is for breakpoint before redefinition
       
    76         int foo = 0; // BREAKPOINT_LINE_BEFORE
       
    77 
       
    78         // invoke tested method after redefinition
       
    79         log.display("Invoking tested methods after redefinition");
       
    80         redefinecls001b.testedStaticMethod();
       
    81         object.testedObjectMethod();
       
    82         printInvocationResult();
       
    83 
       
    84         log.display("\nBreakpoint line after redefinition reached");
       
    85         // next line is for breakpoint after redefinition
       
    86         foo = 1; // BREAKPOINT_LINE_AFTER
       
    87 
       
    88         log.display("Debugee PASSED");
       
    89         return redefinecls001.PASSED;
       
    90     }
       
    91 
       
    92     // print information about kind of invoked methods
       
    93     private static void printInvocationResult() {
       
    94         log.display("Result of methods invokation:");
       
    95         log.display("    constructorInvoked:  " + methodKind(redefinecls001b.constructorInvoked));
       
    96         log.display("    staticMethodInvoked: " + methodKind(redefinecls001b.staticMethodInvoked));
       
    97         log.display("    objectMethodInvoked: " + methodKind(redefinecls001b.objectMethodInvoked));
       
    98     }
       
    99 
       
   100     // return string representation of kind of invoked method
       
   101     private static String methodKind(int kind) {
       
   102         switch (kind) {
       
   103             case redefinecls001b.METHOD_NOT_INVOKED:
       
   104                 return "METHOD_NOT_INVOKED";
       
   105             case redefinecls001b.REDEFINED_METHOD_INVOKED:
       
   106                 return "REDEFINED_METHOD_INVOKED";
       
   107             case redefinecls001b.NOT_REDEFINED_METHOD_INVOKED:
       
   108                 return "NOT_REDEFINED_METHOD_INVOKED";
       
   109             default:
       
   110                 return "UNKNOWN_METHOD_KIND";
       
   111         }
       
   112     }
       
   113 }