• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 public class Main {
18   static class Other {
19   }
20 
21   static class OtherWithClinit {
22     static int a;
23     static {
24       System.out.println("Hello from OtherWithClinit");
25       a = 42;
26     }
27   }
28 
29   static class OtherWithClinit2 {
30     static int a;
31     static {
32       System.out.println("Hello from OtherWithClinit2");
33       a = 43;
34     }
35   }
36 
main(String[] args)37   public static void main(String[] args) {
38     // Call methods twice in case they have a slow path.
39 
40     System.out.println($opt$LoadThisClass());
41     System.out.println($opt$LoadThisClass());
42 
43     System.out.println($opt$LoadOtherClass());
44     System.out.println($opt$LoadOtherClass());
45 
46     System.out.println($opt$LoadSystemClass());
47     System.out.println($opt$LoadSystemClass());
48 
49     $opt$ClinitCheckAndLoad();
50     $opt$ClinitCheckAndLoad();
51 
52     $opt$LoadAndClinitCheck();
53     $opt$LoadAndClinitCheck();
54   }
55 
$opt$LoadThisClass()56   public static Class<?> $opt$LoadThisClass() {
57     return Main.class;
58   }
59 
$opt$LoadOtherClass()60   public static Class<?> $opt$LoadOtherClass() {
61     return Other.class;
62   }
63 
$opt$LoadSystemClass()64   public static Class<?> $opt$LoadSystemClass() {
65     return System.class;
66   }
67 
$opt$ClinitCheckAndLoad()68   public static void $opt$ClinitCheckAndLoad() {
69     System.out.println(OtherWithClinit.a);
70     System.out.println(OtherWithClinit.class);
71   }
72 
$opt$LoadAndClinitCheck()73   public static void $opt$LoadAndClinitCheck() {
74     System.out.println(OtherWithClinit2.class);
75     System.out.println(OtherWithClinit2.a);
76   }
77 }
78