comparison graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/InitTimer.java @ 21551:5324104ac4f3

moved com.oracle.graal.hotspot.jvmci classes to com.oracle.jvmci.hotspot module (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 26 May 2015 17:13:37 +0200
parents
children
comparison
equal deleted inserted replaced
21550:f48a6cea31eb 21551:5324104ac4f3
1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
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 com.oracle.jvmci.hotspot;
24
25 import com.oracle.graal.debug.*;
26
27 import edu.umd.cs.findbugs.annotations.*;
28
29 /**
30 * A facility for timing a step in the runtime initialization sequence. This exists separate from
31 * {@link DebugTimer} as it must be independent from all other Graal code so as to not perturb the
32 * initialization sequence.
33 */
34 public final class InitTimer implements AutoCloseable {
35 final String name;
36 final long start;
37
38 private InitTimer(String name) {
39 this.name = name;
40 this.start = System.currentTimeMillis();
41 System.out.println("START: " + SPACES.substring(0, timerDepth * 2) + name);
42 assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread;
43 timerDepth++;
44 }
45
46 @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "only the initializing thread accesses this field")
47 public void close() {
48 final long end = System.currentTimeMillis();
49 timerDepth--;
50 System.out.println(" DONE: " + SPACES.substring(0, timerDepth * 2) + name + " [" + (end - start) + " ms]");
51 }
52
53 public static InitTimer timer(String name) {
54 return ENABLED ? new InitTimer(name) : null;
55 }
56
57 public static InitTimer timer(String name, Object suffix) {
58 return ENABLED ? new InitTimer(name + suffix) : null;
59 }
60
61 /**
62 * Specifies if initialization timing is enabled. This can only be set via a system property as
63 * the timing facility is used to time initialization of {@link HotSpotOptions}.
64 */
65 private static final boolean ENABLED = Boolean.getBoolean("jvmci.runtime.TimeInit");
66
67 public static int timerDepth = 0;
68 public static final String SPACES = " ";
69
70 /**
71 * Used to assert the invariant that all initialization happens on the same thread.
72 */
73 public static final Thread initializingThread;
74 static {
75 if (ENABLED) {
76 initializingThread = Thread.currentThread();
77 System.out.println("INITIALIZING THREAD: " + initializingThread);
78 } else {
79 initializingThread = null;
80 }
81 }
82 }