Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/HelloWorld.java
41159 views
/*1* Copyright (c) 2000, 2011, 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*22*/2324package sun.jvm.hotspot;2526import java.lang.reflect.*;2728public class HelloWorld {29private static String helloWorldString = "Hello, world!";30private static volatile int helloWorldTrigger = 0;31private static final boolean useMethodInvoke = false;32private static Object lock = new Object();3334public static void main(String[] args) {35int foo = a();3637System.out.println("HelloWorld exiting. a() = " + foo);38}3940private static int a() {41return 1 + b();42}4344private static int b() {45return 1 + c();46}4748private static int c() {49return 1 + d("Hi");50}5152private static int d(String x) {53System.out.println("HelloWorld.d() received \"" + x + "\" as argument");54synchronized(lock) {55if (useMethodInvoke) {56try {57Method method = HelloWorld.class.getMethod("e");58Integer result = (Integer) method.invoke(null, new Object[0]);59return result.intValue();60}61catch (Exception e) {62throw new RuntimeException(e.toString());63}64} else {6566int i = fib(10); // 8967long l = i;68float f = i;69double d = i;70char c = (char) i;71short s = (short) i;72byte b = (byte) i;7374int ret = e();7576System.out.println("Tenth Fibonacci number in all formats: " +77i + ", " +78l + ", " +79f + ", " +80d + ", " +81c + ", " +82s + ", " +83b);8485return ret;86}87}88}8990public static int e() {91System.out.println("Going to sleep...");9293int i = 0;9495while (helloWorldTrigger == 0) {96if (++i == 1000000) {97System.gc();98}99}100101System.out.println(helloWorldString);102103while (helloWorldTrigger != 0) {104}105106return i;107}108109// Tree-recursive implementation for test110public static int fib(int n) {111if (n < 2) {112return 1;113}114return fib(n - 1) + fib(n - 2);115}116}117118119