1 /* |
1 /* |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 package jdk.vm.ci.common; |
23 package jdk.vm.ci.common; |
24 |
24 |
25 import java.util.concurrent.atomic.AtomicInteger; |
25 import java.util.concurrent.atomic.AtomicInteger; |
|
26 |
|
27 import jdk.vm.ci.services.Services; |
26 |
28 |
27 /** |
29 /** |
28 * A facility for timing a step in the runtime initialization sequence. This is independent from all |
30 * A facility for timing a step in the runtime initialization sequence. This is independent from all |
29 * other JVMCI code so as to not perturb the initialization sequence. It is enabled by setting the |
31 * other JVMCI code so as to not perturb the initialization sequence. It is enabled by setting the |
30 * {@code "jvmci.inittimer"} system property to {@code "true"}. |
32 * {@code "jvmci.inittimer"} system property to {@code "true"}. |
56 initializingThread = null; |
58 initializingThread = null; |
57 } |
59 } |
58 } |
60 } |
59 |
61 |
60 public static InitTimer timer(String name) { |
62 public static InitTimer timer(String name) { |
61 return ENABLED ? new InitTimer(name) : null; |
63 return isEnabled() ? new InitTimer(name) : null; |
62 } |
64 } |
63 |
65 |
64 public static InitTimer timer(String name, Object suffix) { |
66 public static InitTimer timer(String name, Object suffix) { |
65 return ENABLED ? new InitTimer(name + suffix) : null; |
67 return isEnabled() ? new InitTimer(name + suffix) : null; |
66 } |
68 } |
67 |
69 |
68 /** |
70 /** |
69 * Specifies if initialization timing is enabled. Note: This property cannot use |
71 * Determines if initialization timing is enabled. Note: This property cannot use |
70 * {@code HotSpotJVMCIRuntime.Option} since that class is not visible from this package. |
72 * {@code HotSpotJVMCIRuntime.Option} since that class is not visible from this package. |
71 */ |
73 */ |
72 private static final boolean ENABLED = Boolean.getBoolean("jvmci.InitTimer"); |
74 private static boolean isEnabled() { |
|
75 if (enabledPropertyValue == null) { |
|
76 enabledPropertyValue = Boolean.parseBoolean(Services.getSavedProperty("jvmci.InitTimer")); |
|
77 nesting = new AtomicInteger(); |
|
78 } |
|
79 return enabledPropertyValue; |
|
80 } |
73 |
81 |
74 public static final AtomicInteger nesting = ENABLED ? new AtomicInteger() : null; |
82 /** |
75 public static final String SPACES = " "; |
83 * Cache for value of {@code jvmci.InitTimer} system property. |
|
84 */ |
|
85 @NativeImageReinitialize private static Boolean enabledPropertyValue; |
|
86 |
|
87 private static AtomicInteger nesting; |
|
88 private static final String SPACES = " "; |
76 |
89 |
77 /** |
90 /** |
78 * Used to assert the invariant that all related initialization happens on the same thread. |
91 * Used to assert the invariant that all related initialization happens on the same thread. |
79 */ |
92 */ |
80 static Thread initializingThread; |
93 static Thread initializingThread; |