Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/HelloWorld.java
41159 views
1
/*
2
* Copyright (c) 2000, 2011, 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
25
package sun.jvm.hotspot;
26
27
import java.lang.reflect.*;
28
29
public class HelloWorld {
30
private static String helloWorldString = "Hello, world!";
31
private static volatile int helloWorldTrigger = 0;
32
private static final boolean useMethodInvoke = false;
33
private static Object lock = new Object();
34
35
public static void main(String[] args) {
36
int foo = a();
37
38
System.out.println("HelloWorld exiting. a() = " + foo);
39
}
40
41
private static int a() {
42
return 1 + b();
43
}
44
45
private static int b() {
46
return 1 + c();
47
}
48
49
private static int c() {
50
return 1 + d("Hi");
51
}
52
53
private static int d(String x) {
54
System.out.println("HelloWorld.d() received \"" + x + "\" as argument");
55
synchronized(lock) {
56
if (useMethodInvoke) {
57
try {
58
Method method = HelloWorld.class.getMethod("e");
59
Integer result = (Integer) method.invoke(null, new Object[0]);
60
return result.intValue();
61
}
62
catch (Exception e) {
63
throw new RuntimeException(e.toString());
64
}
65
} else {
66
67
int i = fib(10); // 89
68
long l = i;
69
float f = i;
70
double d = i;
71
char c = (char) i;
72
short s = (short) i;
73
byte b = (byte) i;
74
75
int ret = e();
76
77
System.out.println("Tenth Fibonacci number in all formats: " +
78
i + ", " +
79
l + ", " +
80
f + ", " +
81
d + ", " +
82
c + ", " +
83
s + ", " +
84
b);
85
86
return ret;
87
}
88
}
89
}
90
91
public static int e() {
92
System.out.println("Going to sleep...");
93
94
int i = 0;
95
96
while (helloWorldTrigger == 0) {
97
if (++i == 1000000) {
98
System.gc();
99
}
100
}
101
102
System.out.println(helloWorldString);
103
104
while (helloWorldTrigger != 0) {
105
}
106
107
return i;
108
}
109
110
// Tree-recursive implementation for test
111
public static int fib(int n) {
112
if (n < 2) {
113
return 1;
114
}
115
return fib(n - 1) + fib(n - 2);
116
}
117
}
118
119