blob: 90ccf3ab2d5d7365ea96508f1b07a0c088e4a0bd [file] [log] [blame]
Nicolas Geoffray424f6762014-11-03 14:51:25 +00001/*
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
17public 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
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
Andreas Gampe166aaee2016-07-18 08:27:23 -070056 public static Class<?> $opt$LoadThisClass() {
Nicolas Geoffray424f6762014-11-03 14:51:25 +000057 return Main.class;
58 }
59
Andreas Gampe166aaee2016-07-18 08:27:23 -070060 public static Class<?> $opt$LoadOtherClass() {
Nicolas Geoffray424f6762014-11-03 14:51:25 +000061 return Other.class;
62 }
63
Andreas Gampe166aaee2016-07-18 08:27:23 -070064 public static Class<?> $opt$LoadSystemClass() {
Nicolas Geoffray424f6762014-11-03 14:51:25 +000065 return System.class;
66 }
67
68 public static void $opt$ClinitCheckAndLoad() {
69 System.out.println(OtherWithClinit.a);
70 System.out.println(OtherWithClinit.class);
71 }
72
73 public static void $opt$LoadAndClinitCheck() {
74 System.out.println(OtherWithClinit2.class);
75 System.out.println(OtherWithClinit2.a);
76 }
77}