author | kvn |
Wed, 01 May 2019 12:31:29 -0700 | |
changeset 54669 | ad45b3802d4e |
parent 50858 | 2d3e99a72541 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
43972 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
package jdk.vm.ci.common; |
|
24 |
||
25 |
import java.util.concurrent.atomic.AtomicInteger; |
|
26 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
27 |
import jdk.vm.ci.services.Services; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
28 |
|
43972 | 29 |
/** |
30 |
* A facility for timing a step in the runtime initialization sequence. This is independent from all |
|
31 |
* other JVMCI code so as to not perturb the initialization sequence. It is enabled by setting the |
|
32 |
* {@code "jvmci.inittimer"} system property to {@code "true"}. |
|
33 |
*/ |
|
34 |
public final class InitTimer implements AutoCloseable { |
|
35 |
private final String name; |
|
36 |
private final long start; |
|
37 |
||
38 |
private InitTimer(String name) { |
|
39 |
int n = nesting.getAndIncrement(); |
|
40 |
if (n == 0) { |
|
41 |
initializingThread = Thread.currentThread(); |
|
42 |
System.out.println("INITIALIZING THREAD: " + initializingThread); |
|
43 |
} else { |
|
44 |
assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread; |
|
45 |
} |
|
46 |
this.name = name; |
|
47 |
this.start = System.currentTimeMillis(); |
|
48 |
System.out.println("START: " + SPACES.substring(0, n * 2) + name); |
|
49 |
} |
|
50 |
||
50858 | 51 |
@Override |
43972 | 52 |
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "only the initializing thread accesses this field") |
53 |
public void close() { |
|
54 |
final long end = System.currentTimeMillis(); |
|
55 |
int n = nesting.decrementAndGet(); |
|
56 |
System.out.println(" DONE: " + SPACES.substring(0, n * 2) + name + " [" + (end - start) + " ms]"); |
|
57 |
if (n == 0) { |
|
58 |
initializingThread = null; |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
public static InitTimer timer(String name) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
63 |
return isEnabled() ? new InitTimer(name) : null; |
43972 | 64 |
} |
65 |
||
66 |
public static InitTimer timer(String name, Object suffix) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
67 |
return isEnabled() ? new InitTimer(name + suffix) : null; |
43972 | 68 |
} |
69 |
||
70 |
/** |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
71 |
* Determines if initialization timing is enabled. Note: This property cannot use |
43972 | 72 |
* {@code HotSpotJVMCIRuntime.Option} since that class is not visible from this package. |
73 |
*/ |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
74 |
private static boolean isEnabled() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
75 |
if (enabledPropertyValue == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
76 |
enabledPropertyValue = Boolean.parseBoolean(Services.getSavedProperty("jvmci.InitTimer")); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
77 |
nesting = new AtomicInteger(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
78 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
79 |
return enabledPropertyValue; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
80 |
} |
43972 | 81 |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
82 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
83 |
* Cache for value of {@code jvmci.InitTimer} system property. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
84 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
85 |
@NativeImageReinitialize private static Boolean enabledPropertyValue; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
86 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
87 |
private static AtomicInteger nesting; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50858
diff
changeset
|
88 |
private static final String SPACES = " "; |
43972 | 89 |
|
90 |
/** |
|
91 |
* Used to assert the invariant that all related initialization happens on the same thread. |
|
92 |
*/ |
|
93 |
static Thread initializingThread; |
|
94 |
} |