annotate agent/src/share/classes/sun/jvm/hotspot/HelloWorld.java @ 6972:bd7a7ce2e264

6830717: replay of compilations would help with debugging Summary: When java process crashed in compiler thread, repeat the compilation process will help finding root cause. This is done with using SA dump application class data and replay data from core dump, then use debug version of jvm to recompile the problematic java method. Reviewed-by: kvn, twisti, sspitsyn Contributed-by: yumin.qi@oracle.com
author minqi
date Mon, 12 Nov 2012 14:03:53 -0800
parents 37be97a58393
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2471
37be97a58393 7010849: 5/5 Extraneous javac source/target options when building sa-jdi
andrew
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.lang.reflect.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 public class HelloWorld {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 private static String helloWorldString = "Hello, world!";
a61af66fc99e Initial load
duke
parents:
diff changeset
31 private static volatile int helloWorldTrigger = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private static final boolean useMethodInvoke = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private static Object lock = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 int foo = a();
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 System.out.println("HelloWorld exiting. a() = " + foo);
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static int a() {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 return 1 + b();
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private static int b() {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 return 1 + c();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private static int c() {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return 1 + d("Hi");
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private static int d(String x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 System.out.println("HelloWorld.d() received \"" + x + "\" as argument");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 synchronized(lock) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 if (useMethodInvoke) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 try {
2471
37be97a58393 7010849: 5/5 Extraneous javac source/target options when building sa-jdi
andrew
parents: 1552
diff changeset
58 Method method = HelloWorld.class.getMethod("e");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59 Integer result = (Integer) method.invoke(null, new Object[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return result.intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 throw new RuntimeException(e.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 int i = fib(10); // 89
a61af66fc99e Initial load
duke
parents:
diff changeset
68 long l = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 float f = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 double d = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 char c = (char) i;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 short s = (short) i;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 byte b = (byte) i;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 int ret = e();
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 System.out.println("Tenth Fibonacci number in all formats: " +
a61af66fc99e Initial load
duke
parents:
diff changeset
78 i + ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
79 l + ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
80 f + ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
81 d + ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
82 c + ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
83 s + ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
84 b);
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public static int e() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 System.out.println("Going to sleep...");
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 while (helloWorldTrigger == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (++i == 1000000) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 System.gc();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 System.out.println(helloWorldString);
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 while (helloWorldTrigger != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Tree-recursive implementation for test
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public static int fib(int n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if (n < 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return fib(n - 1) + fib(n - 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }