jdk/test/demo/jvmti/hprof/HelloWorld.java
author xdono
Tue, 28 Jul 2009 12:12:54 -0700
changeset 3288 db82a42da273
parent 3223 24e98ad0c62e
child 5506 202f599c92aa
permissions -rw-r--r--
6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
3288
db82a42da273 6862919: Update copyright year
xdono
parents: 3223
diff changeset
     2
 * Copyright 2004-2009 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/* HelloWorld:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *
3223
24e98ad0c62e 6855551: java -Xrunhprof crashes when running with classes compiled with targed=7
ohair
parents: 2
diff changeset
    27
 *   Sample target application for HPROF tests
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/* Just some classes that create a variety of references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
class AAAA {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    public int                  AAAA_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    public static int           AAAA_si;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public Object               AAAA_j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    public static Object        AAAA_sj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    public long                 AAAA_k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    public static long          AAAA_sk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
interface IIII {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    Object o = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
class BBBB extends AAAA implements IIII {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public byte                 BBBB_ii;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static byte          BBBB_sii;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public Object               BBBB_jj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static Object        BBBB_sjj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public short                BBBB_kk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static short         BBBB_skk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
class REFS {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static String s1    = new String("REFS_string1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private String is2          = new String("REFS_string2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static String s3    = new String("REFS_string3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static String s4    = new String("REFS_string4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private String is5          = new String("REFS_string5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private AAAA aaaa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private BBBB bbbb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public void test() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        aaaa    = new AAAA();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        bbbb    = new BBBB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        aaaa.AAAA_i     = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        AAAA.AAAA_si    = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        aaaa.AAAA_j     = s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        AAAA.AAAA_sj    = is2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        aaaa.AAAA_k     = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        AAAA.AAAA_sk    = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        bbbb.BBBB_ii    = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        BBBB.BBBB_sii   = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        bbbb.BBBB_jj    = s3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        BBBB.BBBB_sjj   = s4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        bbbb.BBBB_kk    = 55;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        BBBB.BBBB_skk   = 66;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        bbbb.AAAA_i     = 111;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        bbbb.AAAA_j     = is5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        bbbb.AAAA_k     = 555;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
/* Fairly simple hello world program that does some exercises first. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
public class HelloWorld {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        /* References exercise. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        REFS r = new REFS();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        r.test();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        /* Use a generic type exercise. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        java.util.List<String> l = new java.util.ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        String.format("%s", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        /* Create a class that has lots of different bytecodes exercise. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                     /* (Don't run it!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        UseAllBytecodes x = new UseAllBytecodes(1,2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        /* Just some code with branches exercise. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            if ( args.length == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                System.out.println("No arguments passed in (doesn't matter)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                System.out.println("Arguments passed in (doesn't matter)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } catch ( Throwable e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            System.out.println("ERROR: System.out.println() did a throw");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            System.out.println("Hello, world!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}