Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.common/src/jdk/vm/ci/common/InitTimer.java @ 24234:ea6f94ab283b default tip
Added tag jvmci-0.36 for changeset 8128b98d4736
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 18 Sep 2017 18:49:45 +0200 |
parents | 9e1235406b59 |
children |
rev | line source |
---|---|
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21526
diff
changeset
|
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
23393
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
23306
diff
changeset
|
23 package jdk.vm.ci.common; |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
22745
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
25 import java.util.concurrent.atomic.AtomicInteger; |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
26 |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 /** |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22299
diff
changeset
|
28 * A facility for timing a step in the runtime initialization sequence. This is independent from all |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22299
diff
changeset
|
29 * other JVMCI code so as to not perturb the initialization sequence. It is enabled by setting the |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22299
diff
changeset
|
30 * {@code "jvmci.inittimer"} system property to {@code "true"}. |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 */ |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
16399
diff
changeset
|
32 public final class InitTimer implements AutoCloseable { |
23700
9e1235406b59
[Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents:
23398
diff
changeset
|
33 private final String name; |
9e1235406b59
[Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents:
23398
diff
changeset
|
34 private final long start; |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 private InitTimer(String name) { |
22745
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
37 int n = nesting.getAndIncrement(); |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
38 if (n == 0) { |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
39 initializingThread = Thread.currentThread(); |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
40 System.out.println("INITIALIZING THREAD: " + initializingThread); |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
41 } else { |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
42 assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread; |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
43 } |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 this.name = name; |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 this.start = System.currentTimeMillis(); |
22745
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
46 System.out.println("START: " + SPACES.substring(0, n * 2) + name); |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 } |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "only the initializing thread accesses this field") |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 public void close() { |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 final long end = System.currentTimeMillis(); |
22745
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
52 int n = nesting.decrementAndGet(); |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
53 System.out.println(" DONE: " + SPACES.substring(0, n * 2) + name + " [" + (end - start) + " ms]"); |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
54 if (n == 0) { |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
55 initializingThread = null; |
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
56 } |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 } |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 public static InitTimer timer(String name) { |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 return ENABLED ? new InitTimer(name) : null; |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 } |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 public static InitTimer timer(String name, Object suffix) { |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 return ENABLED ? new InitTimer(name + suffix) : null; |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 } |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 /** |
23398
3e8ce13f4e12
minimize diff to jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23393
diff
changeset
|
68 * Specifies if initialization timing is enabled. Note: This property cannot use |
3e8ce13f4e12
minimize diff to jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23393
diff
changeset
|
69 * {@code HotSpotJVMCIRuntime.Option} since that class is not visible from this package. |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 */ |
23306
7b09dede4552
JVMCI options should not use System.getProperty() directly (JDK-8146820)
Doug Simon <doug.simon@oracle.com>
parents:
22745
diff
changeset
|
71 private static final boolean ENABLED = Boolean.getBoolean("jvmci.InitTimer"); |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 |
22745
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
73 public static final AtomicInteger nesting = ENABLED ? new AtomicInteger() : null; |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 public static final String SPACES = " "; |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 |
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 /** |
22745
9ed36a1fec52
JVMCI compiler initialization can happen on different thread than JVMCI initialization
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
77 * Used to assert the invariant that all related initialization happens on the same thread. |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 */ |
23700
9e1235406b59
[Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents:
23398
diff
changeset
|
79 static Thread initializingThread; |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 } |