annotate jvmci/jdk.vm.ci.inittimer/src/jdk/vm/ci/inittimer/InitTimer.java @ 22672:1bbd4a7c274b

Rename jdk.internal.jvmci to jdk.vm.ci
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 08 Oct 2015 17:28:41 -0700
parents jvmci/jdk.internal.jvmci.inittimer/src/jdk/internal/jvmci/inittimer/InitTimer.java@4f6caa445b92
children 9ed36a1fec52
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 */
22672
1bbd4a7c274b Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22398
diff changeset
23 package jdk.vm.ci.inittimer;
16006
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 /**
22398
4f6caa445b92 moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents: 22299
diff changeset
26 * 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
27 * 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
28 * {@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
29 */
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
30 public final class InitTimer implements AutoCloseable {
16006
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 final String name;
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 final long start;
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 private InitTimer(String name) {
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 this.name = name;
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 this.start = System.currentTimeMillis();
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 System.out.println("START: " + SPACES.substring(0, timerDepth * 2) + name);
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread;
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 timerDepth++;
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 }
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 @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
43 public void close() {
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 final long end = System.currentTimeMillis();
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 timerDepth--;
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 System.out.println(" DONE: " + SPACES.substring(0, timerDepth * 2) + name + " [" + (end - start) + " ms]");
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 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
50 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
51 }
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 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
54 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
55 }
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 /**
22398
4f6caa445b92 moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents: 22299
diff changeset
58 * Specifies if initialization timing is enabled.
16006
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 */
22398
4f6caa445b92 moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents: 22299
diff changeset
60 private static final boolean ENABLED = Boolean.getBoolean("jvmci.inittimer") || Boolean.getBoolean("jvmci.runtime.TimeInit");
16006
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 public static int timerDepth = 0;
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 public static final String SPACES = " ";
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64
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 * Used to assert the invariant that all initialization happens on the same thread.
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 */
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68 public static final Thread initializingThread;
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 static {
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 if (ENABLED) {
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 initializingThread = Thread.currentThread();
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 System.out.println("INITIALIZING THREAD: " + initializingThread);
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 } else {
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 initializingThread = null;
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 }
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 }