author | vlivanov |
Mon, 29 Sep 2014 09:32:15 -0700 | |
changeset 26916 | 8a1deee4f9b4 |
parent 25641 | d99065e4572b |
child 30859 | 76147e537436 |
permissions | -rw-r--r-- |
25641
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
1 |
/* |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
4 |
* |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
10 |
* |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
15 |
* accompanied this code). |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
16 |
* |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
20 |
* |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
23 |
* questions. |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
24 |
*/ |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
25 |
package java.lang.invoke; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
26 |
|
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
27 |
import java.lang.reflect.Method; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
28 |
import java.util.Properties; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
29 |
import sun.hotspot.WhiteBox; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
30 |
|
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
31 |
public class StableConfiguration { |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
32 |
static final WhiteBox WB = WhiteBox.getWhiteBox(); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
33 |
static final boolean isStableEnabled; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
34 |
static final boolean isServerWithStable; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
35 |
|
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
36 |
static { |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
37 |
Boolean value = WB.getBooleanVMFlag("FoldStableValues"); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
38 |
isStableEnabled = (value == null ? false : value); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
39 |
isServerWithStable = isStableEnabled && get(); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
40 |
System.out.println("@Stable: " + (isStableEnabled ? "enabled" : "disabled")); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
41 |
System.out.println("Server Compiler: " + get()); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
42 |
} |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
43 |
|
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
44 |
// ::get() is among immediately compiled methods. |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
45 |
static boolean get() { |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
46 |
try { |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
47 |
Method m = StableConfiguration.class.getDeclaredMethod("get"); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
48 |
int level = WB.getMethodCompilationLevel(m); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
49 |
if (level > 0) { |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
50 |
return (level == 4); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
51 |
} else { |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
52 |
String javaVM = System.getProperty("java.vm.name", ""); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
53 |
if (javaVM.contains("Server")) return true; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
54 |
if (javaVM.contains("Client")) return false; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
55 |
throw new Error("Unknown VM type: "+javaVM); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
56 |
} |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
57 |
} catch (NoSuchMethodException e) { |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
58 |
throw new Error(e); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
59 |
} |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
60 |
} |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
61 |
|
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
diff
changeset
|
62 |
} |