1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */
18 
19 package org.apache.harmony.jpda.tests.jdwp.Deoptimization;
20 
21 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
22 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
23 
24 /**
25  * Debuggee for DeoptimizationWithExceptionHandlingTest.
26  */
27 public class DeoptimizationWithExceptionHandlingDebuggee extends SyncDebuggee {
28     public static final int SUCCESS_RESULT = 1;
29     public static final int FAILURE_RESULT = 0;
30 
main(String[] args)31     public static void main(String[] args) {
32         runDebuggee(DeoptimizationWithExceptionHandlingDebuggee.class);
33     }
34 
run()35     public void run() {
36         logWriter.println("--> DeoptimizationWithExceptionHandlingDebuggee started");
37         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
38 
39         // Wait for test setup
40         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
41 
42         int result = runTest();
43         logWriter.println("Result == " + result);
44 
45         // Send result to test.
46         synchronizer.sendMessage(Integer.toString(result));
47 
48         logWriter.println("--> DeoptimizationWithExceptionHandlingDebuggee finished");
49     }
50 
51     /**
52      * This method will catch the NullPointerException after deoptimization happened.
53      */
runTest()54     private static int runTest() {
55         int result = FAILURE_RESULT;
56         try {
57             runBreakpointMethodThenThrowNPE();
58             result = FAILURE_RESULT;
59         } catch (NullPointerException e) {
60             result = SUCCESS_RESULT;
61         }
62         return result;
63     }
64 
65     /**
66      * This method will throw a NullPointerException after deoptimization happened.
67      */
runBreakpointMethodThenThrowNPE()68     private static void runBreakpointMethodThenThrowNPE() {
69         runBreakpointMethod();
70         throw new NullPointerException();
71     }
72 
73     /**
74      * This method will be the starting point of stack deoptimization.
75      */
runBreakpointMethod()76     private static void runBreakpointMethod() {
77         breakpointMethod();
78     }
79 
breakpointMethod()80     private static void breakpointMethod() {
81         System.out.println("breakpointMethod");
82     }
83 
84 }
85