annotate jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugScope.java @ 21798:395ac43a8578

moved JVMCI sources from graal/ to jvmci/ directory
author Doug Simon <doug.simon@oracle.com>
date Tue, 09 Jun 2015 00:22:49 +0200
parents graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugScope.java@f5b549811bac
children 90e3fecd4143
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21454
diff changeset
23 package com.oracle.jvmci.debug.internal;
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
24
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
25 import java.io.*;
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
26 import java.util.*;
4353
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
27 import java.util.concurrent.*;
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21454
diff changeset
29 import com.oracle.jvmci.debug.*;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21454
diff changeset
30
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
31 public final class DebugScope implements Debug.Scope {
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
32
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
33 private final class IndentImpl implements Indent {
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
34
11400
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
35 private static final String INDENTATION_INCREMENT = " ";
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
36
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
37 final String indent;
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
38 final IndentImpl parentIndent;
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
39
13551
ba72961e0d41 removed ability for the log indentation mechanism to also enable/disable logging which should be controlled only by the -G:Log command line option
Doug Simon <doug.simon@oracle.com>
parents: 13547
diff changeset
40 IndentImpl(IndentImpl parentIndent) {
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
41 this.parentIndent = parentIndent;
11400
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
42 this.indent = (parentIndent == null ? "" : parentIndent.indent + INDENTATION_INCREMENT);
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
43 }
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
44
16405
9bfc4247262f send log output to native tty
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16297
diff changeset
45 private void printScopeName(StringBuilder str) {
11400
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
46 if (logScopeName) {
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
47 if (parentIndent != null) {
16405
9bfc4247262f send log output to native tty
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16297
diff changeset
48 parentIndent.printScopeName(str);
11400
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
49 }
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
50 str.append(indent).append("[thread:").append(Thread.currentThread().getId()).append("] scope: ").append(getQualifiedName()).append(System.lineSeparator());
11400
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
51 logScopeName = false;
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
52 }
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
53 }
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
54
16463
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
55 public void log(int logLevel, String msg, Object... args) {
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
56 if (isLogEnabled(logLevel)) {
16405
9bfc4247262f send log output to native tty
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16297
diff changeset
57 StringBuilder str = new StringBuilder();
9bfc4247262f send log output to native tty
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16297
diff changeset
58 printScopeName(str);
9bfc4247262f send log output to native tty
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16297
diff changeset
59 str.append(indent);
18875
d71bf1009d71 Fix indentation of multi-line strings passed to Debug.log
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18703
diff changeset
60 String result = args.length == 0 ? msg : String.format(msg, args);
d71bf1009d71 Fix indentation of multi-line strings passed to Debug.log
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18703
diff changeset
61 String lineSep = System.lineSeparator();
d71bf1009d71 Fix indentation of multi-line strings passed to Debug.log
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18703
diff changeset
62 str.append(result.replace(lineSep, lineSep.concat(indent)));
d71bf1009d71 Fix indentation of multi-line strings passed to Debug.log
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18703
diff changeset
63 str.append(lineSep);
16405
9bfc4247262f send log output to native tty
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16297
diff changeset
64 output.append(str);
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
65 lastUsedIndent = this;
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
66 }
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
67 }
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
68
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14586
diff changeset
69 IndentImpl indent() {
13551
ba72961e0d41 removed ability for the log indentation mechanism to also enable/disable logging which should be controlled only by the -G:Log command line option
Doug Simon <doug.simon@oracle.com>
parents: 13547
diff changeset
70 lastUsedIndent = new IndentImpl(this);
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
71 return lastUsedIndent;
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
72 }
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
73
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
74 @Override
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14586
diff changeset
75 public void close() {
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
76 if (parentIndent != null) {
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
77 lastUsedIndent = parentIndent;
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
78 }
13142
401830ff96f4 some improvements in Debug logging
Erik Eckstein <erik.eckstein@oracle.com>
parents: 11733
diff changeset
79 }
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
80 }
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
81
14017
e34f406850e5 ThreadLocals should be final
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13551
diff changeset
82 private static final ThreadLocal<DebugScope> instanceTL = new ThreadLocal<>();
e34f406850e5 ThreadLocals should be final
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13551
diff changeset
83 private static final ThreadLocal<DebugScope> lastClosedTL = new ThreadLocal<>();
e34f406850e5 ThreadLocals should be final
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13551
diff changeset
84 private static final ThreadLocal<DebugConfig> configTL = new ThreadLocal<>();
e34f406850e5 ThreadLocals should be final
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13551
diff changeset
85 private static final ThreadLocal<Throwable> lastExceptionThrownTL = new ThreadLocal<>();
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
86
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
87 private final DebugScope parent;
13163
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
88 private final DebugConfig parentConfig;
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
89 private final boolean sandbox;
11400
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
90 private IndentImpl lastUsedIndent;
37446655527c changed log indentation increment to 2 spaces
Doug Simon <doug.simon@oracle.com>
parents: 11382
diff changeset
91 private boolean logScopeName;
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
92
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
93 private final Object[] context;
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
94
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
95 private DebugValueMap valueMap;
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
96
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
97 private String qualifiedName;
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
98 private final String unqualifiedName;
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
99
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
100 private static final char SCOPE_SEP = '.';
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
101
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
102 private boolean meterEnabled;
4394
cf609017d3d4 Fixed warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4392
diff changeset
103 private boolean timeEnabled;
15581
0dc0926cf0d8 added -G:TrackMemUse for measuring memory usage within scopes
Doug Simon <doug.simon@oracle.com>
parents: 14873
diff changeset
104 private boolean memUseTrackingEnabled;
16144
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
105 private boolean verifyEnabled;
16463
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
106
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
107 private int currentDumpLevel;
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
108 private int currentLogLevel;
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109
5302
55bf72fafc41 (preliminary) logging to file (-G:LogFile=asdf.txt)
Lukas Stadler <lukas.stadler@jku.at>
parents: 5134
diff changeset
110 private PrintStream output;
55bf72fafc41 (preliminary) logging to file (-G:LogFile=asdf.txt)
Lukas Stadler <lukas.stadler@jku.at>
parents: 5134
diff changeset
111
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
112 public static DebugScope getInstance() {
4361
18b52fec79f1 Completed exception interception.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4357
diff changeset
113 DebugScope result = instanceTL.get();
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
114 if (result == null) {
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
115 DebugScope topLevelDebugScope = new DebugScope(Thread.currentThread());
4406
961895157a38 Tentative implementation of Meter and Time.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4394
diff changeset
116 instanceTL.set(topLevelDebugScope);
961895157a38 Tentative implementation of Meter and Time.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4394
diff changeset
117 return topLevelDebugScope;
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
118 } else {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
119 return result;
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
120 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
121 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
122
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
123 public static DebugConfig getConfig() {
4361
18b52fec79f1 Completed exception interception.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4357
diff changeset
124 return configTL.get();
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
125 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
126
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
127 static final Object[] EMPTY_CONTEXT = new Object[0];
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
128
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
129 private DebugScope(Thread thread) {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
130 this(thread.getName(), null, false);
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
131 computeValueMap(thread.getName());
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
132 DebugValueMap.registerTopLevel(getValueMap());
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
133 }
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
134
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
135 private DebugScope(String unqualifiedName, DebugScope parent, boolean sandbox, Object... context) {
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
136 this.parent = parent;
13163
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
137 this.sandbox = sandbox;
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
138 this.parentConfig = getConfig();
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
139 this.context = context;
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
140 this.unqualifiedName = unqualifiedName;
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
141 if (parent != null) {
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
142 logScopeName = !unqualifiedName.equals("");
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
143 } else {
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
144 logScopeName = true;
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
145 }
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
146
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
147 // Be pragmatic: provide a default log stream to prevent a crash if the stream is not
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
148 // set while logging
16405
9bfc4247262f send log output to native tty
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16297
diff changeset
149 this.output = TTY.cachedOut;
4484
14a00ee82980 Implement eager type resolving.
Andreas Woess <andreas.woess@jku.at>
parents: 4477
diff changeset
150 assert context != null;
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
151 }
5134
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
152
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
153 private void computeValueMap(String name) {
5134
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
154 if (parent != null) {
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
155 for (DebugValueMap child : parent.getValueMap().getChildren()) {
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
156 if (child.getName().equals(name)) {
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
157 this.valueMap = child;
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
158 return;
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
159 }
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
160 }
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
161 this.valueMap = new DebugValueMap(name);
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
162 parent.getValueMap().addChild(this.valueMap);
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
163 } else {
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
164 this.valueMap = new DebugValueMap(name);
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
165 }
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
166 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
167
13163
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
168 public void close() {
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
169 instanceTL.set(parent);
13547
8ea968b6dba9 fix handling of sandboxed debug scopes (don't destroy parent flags)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13197
diff changeset
170 configTL.set(parentConfig);
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
171 lastClosedTL.set(this);
13163
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
172 }
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
173
16463
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
174 public boolean isDumpEnabled(int dumpLevel) {
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
175 assert dumpLevel > 0;
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
176 return currentDumpLevel >= dumpLevel;
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
177 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
178
18690
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
179 /**
18703
41d12b67bc9e Improve javadoc
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18690
diff changeset
180 * Enable dumping at the new {@code dumpLevel} for the remainder of enclosing scopes. This only
41d12b67bc9e Improve javadoc
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18690
diff changeset
181 * works if a {@link TopLevelDebugConfig} was installed at a higher scope.
18690
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
182 *
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
183 * @param dumpLevel
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
184 */
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
185 public static void setDumpLevel(int dumpLevel) {
18703
41d12b67bc9e Improve javadoc
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18690
diff changeset
186 TopLevelDebugConfig config = fetchTopLevelDebugConfig("setDebugLevel");
18690
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
187 if (config != null) {
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
188 config.override(DelegatingDebugConfig.Level.DUMP, dumpLevel);
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
189 recursiveUpdateFlags();
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
190 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
191 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
192
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
193 /**
18703
41d12b67bc9e Improve javadoc
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18690
diff changeset
194 * Enable logging at the new {@code logLevel} for the remainder of enclosing scopes. This only
41d12b67bc9e Improve javadoc
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18690
diff changeset
195 * works if a {@link TopLevelDebugConfig} was installed at a higher scope.
18690
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
196 *
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
197 * @param logLevel
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
198 */
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
199 public static void setLogLevel(int logLevel) {
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
200 TopLevelDebugConfig config = fetchTopLevelDebugConfig("setLogLevel");
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
201 if (config != null) {
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
202 config.override(DelegatingDebugConfig.Level.LOG, logLevel);
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
203 config.delegate(DelegatingDebugConfig.Feature.LOG_METHOD);
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
204 recursiveUpdateFlags();
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
205 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
206 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
207
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
208 private static void recursiveUpdateFlags() {
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
209 DebugScope c = DebugScope.getInstance();
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
210 while (c != null) {
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
211 c.updateFlags();
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
212 c = c.parent;
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
213 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
214 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
215
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
216 private static TopLevelDebugConfig fetchTopLevelDebugConfig(String msg) {
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
217 DebugConfig config = getConfig();
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
218 if (config instanceof TopLevelDebugConfig) {
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
219 return (TopLevelDebugConfig) config;
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
220 } else {
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
221 if (config == null) {
18901
06536c3846e7 Emit warnings to TTY instead of System.out
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18875
diff changeset
222 TTY.println("DebugScope.%s ignored because debugging is disabled", msg);
18690
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
223 } else {
18901
06536c3846e7 Emit warnings to TTY instead of System.out
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18875
diff changeset
224 TTY.println("DebugScope.%s ignored because top level delegate config missing", msg);
18690
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
225 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
226 return null;
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
227 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
228 }
abcff66a23b0 Add ability to programmatically set the dump level
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16463
diff changeset
229
16144
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
230 public boolean isVerifyEnabled() {
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
231 return verifyEnabled;
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
232 }
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
233
16463
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
234 public boolean isLogEnabled(int logLevel) {
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
235 assert logLevel > 0;
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
236 return currentLogLevel >= logLevel;
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
237 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
238
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
239 public boolean isMeterEnabled() {
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
240 return meterEnabled;
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
241 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
242
4394
cf609017d3d4 Fixed warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4392
diff changeset
243 public boolean isTimeEnabled() {
cf609017d3d4 Fixed warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4392
diff changeset
244 return timeEnabled;
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
245 }
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
246
15581
0dc0926cf0d8 added -G:TrackMemUse for measuring memory usage within scopes
Doug Simon <doug.simon@oracle.com>
parents: 14873
diff changeset
247 public boolean isMemUseTrackingEnabled() {
0dc0926cf0d8 added -G:TrackMemUse for measuring memory usage within scopes
Doug Simon <doug.simon@oracle.com>
parents: 14873
diff changeset
248 return memUseTrackingEnabled;
0dc0926cf0d8 added -G:TrackMemUse for measuring memory usage within scopes
Doug Simon <doug.simon@oracle.com>
parents: 14873
diff changeset
249 }
0dc0926cf0d8 added -G:TrackMemUse for measuring memory usage within scopes
Doug Simon <doug.simon@oracle.com>
parents: 14873
diff changeset
250
16463
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
251 public void log(int logLevel, String msg, Object... args) {
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
252 if (isLogEnabled(logLevel)) {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
253 getLastUsedIndent().log(logLevel, msg, args);
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
254 }
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
255 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
256
16463
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
257 public void dump(int dumpLevel, Object object, String formatString, Object... args) {
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
258 if (isDumpEnabled(dumpLevel)) {
4363
7462c3600c3a Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4362
diff changeset
259 DebugConfig config = getConfig();
7462c3600c3a Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4362
diff changeset
260 if (config != null) {
7462c3600c3a Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4362
diff changeset
261 String message = String.format(formatString, args);
7462c3600c3a Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4362
diff changeset
262 for (DebugDumpHandler dumpHandler : config.dumpHandlers()) {
4362
ed69fd347566 Added DebugDumpHandler interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4361
diff changeset
263 dumpHandler.dump(object, message);
ed69fd347566 Added DebugDumpHandler interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4361
diff changeset
264 }
ed69fd347566 Added DebugDumpHandler interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4361
diff changeset
265 }
ed69fd347566 Added DebugDumpHandler interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4361
diff changeset
266 }
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
267 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
268
6570
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
269 /**
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
270 * This method exists mainly to allow a debugger (e.g., Eclipse) to force dump a graph.
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
271 */
21454
0a50a8e82e1b Support string formatting in forceDump
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 21140
diff changeset
272 public static void forceDump(Object object, String format, Object... args) {
6570
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
273 DebugConfig config = getConfig();
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
274 if (config != null) {
21454
0a50a8e82e1b Support string formatting in forceDump
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 21140
diff changeset
275 String message = String.format(format, args);
6570
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
276 for (DebugDumpHandler dumpHandler : config.dumpHandlers()) {
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
277 dumpHandler.dump(object, message);
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
278 }
11733
cb5df1879500 added warning about ignored forced graph dump
Doug Simon <doug.simon@oracle.com>
parents: 11616
diff changeset
279 } else {
18901
06536c3846e7 Emit warnings to TTY instead of System.out
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18875
diff changeset
280 TTY.println("Forced dump ignored because debugging is disabled - use -G:Dump=xxx option");
6570
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
281 }
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
282 }
d4f5301e9c7b added method to DebugScope to simplify dumping of a graph from with Eclipse
Doug Simon <doug.simon@oracle.com>
parents: 5856
diff changeset
283
9199
2ff3499d408e enhanced support for sandboxed debug scope such that their debug config can be specified
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
284 /**
16297
b9236eaecf4c simplified DebugVerifyHandler API to be closer to DebugDumpHandler
Doug Simon <doug.simon@oracle.com>
parents: 16193
diff changeset
285 * @see Debug#verify(Object, String)
16144
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
286 */
16297
b9236eaecf4c simplified DebugVerifyHandler API to be closer to DebugDumpHandler
Doug Simon <doug.simon@oracle.com>
parents: 16193
diff changeset
287 public void verify(Object object, String formatString, Object... args) {
16144
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
288 if (isVerifyEnabled()) {
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
289 DebugConfig config = getConfig();
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
290 if (config != null) {
16297
b9236eaecf4c simplified DebugVerifyHandler API to be closer to DebugDumpHandler
Doug Simon <doug.simon@oracle.com>
parents: 16193
diff changeset
291 String message = String.format(formatString, args);
16144
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
292 for (DebugVerifyHandler handler : config.verifyHandlers()) {
16297
b9236eaecf4c simplified DebugVerifyHandler API to be closer to DebugDumpHandler
Doug Simon <doug.simon@oracle.com>
parents: 16193
diff changeset
293 handler.verify(object, message);
16144
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
294 }
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
295 }
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
296 }
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
297 }
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
298
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
299 /**
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
300 * Creates and enters a new debug scope which is either a child of the current scope or a
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
301 * disjoint top level scope.
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14586
diff changeset
302 *
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
303 * @param name the name of the new scope
13547
8ea968b6dba9 fix handling of sandboxed debug scopes (don't destroy parent flags)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13197
diff changeset
304 * @param sandboxConfig the configuration to use for a new top level scope, or null if the new
8ea968b6dba9 fix handling of sandboxed debug scopes (don't destroy parent flags)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13197
diff changeset
305 * scope should be a child scope
14109
85969b1aba78 Use a forceLog scope for LinearScan.reportFailure. Remove @SuppressWarnings on DebugScope.scope
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14017
diff changeset
306 * @param newContextObjects objects to be appended to the debug context
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
307 * @return the new scope which will be exited when its {@link #close()} method is called
9199
2ff3499d408e enhanced support for sandboxed debug scope such that their debug config can be specified
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
308 */
14586
d2fe05d5cc96 added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents: 14109
diff changeset
309 public DebugScope scope(CharSequence name, DebugConfig sandboxConfig, Object... newContextObjects) {
13163
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
310 DebugScope newScope = null;
13547
8ea968b6dba9 fix handling of sandboxed debug scopes (don't destroy parent flags)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13197
diff changeset
311 if (sandboxConfig != null) {
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
312 newScope = new DebugScope(name.toString(), this, true, newContextObjects);
13547
8ea968b6dba9 fix handling of sandboxed debug scopes (don't destroy parent flags)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13197
diff changeset
313 configTL.set(sandboxConfig);
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
314 } else {
14586
d2fe05d5cc96 added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents: 14109
diff changeset
315 newScope = this.createChild(name.toString(), newContextObjects);
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
316 }
13163
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
317 instanceTL.set(newScope);
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
318 newScope.updateFlags();
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
319 return newScope;
4369
efc430d943c0 Drafted regexp filters. Rewrote logging statements of floating read phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4363
diff changeset
320 }
efc430d943c0 Drafted regexp filters. Rewrote logging statements of floating read phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4363
diff changeset
321
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
322 public RuntimeException handle(Throwable e) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
323 DebugScope lastClosed = lastClosedTL.get();
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
324 assert lastClosed.parent == this : "Debug.handle() used with no matching Debug.scope(...) or Debug.sandbox(...)";
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
325 if (e != lastExceptionThrownTL.get()) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
326 RuntimeException newException = null;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
327 instanceTL.set(lastClosed);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
328 try (DebugScope s = lastClosed) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
329 newException = s.interceptException(e);
4353
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
330 }
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
331 assert instanceTL.get() == this;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
332 assert lastClosed == lastClosedTL.get();
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
333 if (newException == null) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
334 lastExceptionThrownTL.set(e);
4361
18b52fec79f1 Completed exception interception.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4357
diff changeset
335 } else {
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
336 lastExceptionThrownTL.set(newException);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
337 throw newException;
4361
18b52fec79f1 Completed exception interception.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4357
diff changeset
338 }
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
339 }
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
340 if (e instanceof Error) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
341 throw (Error) e;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
342 }
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
343 if (e instanceof RuntimeException) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
344 throw (RuntimeException) e;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
345 }
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
346 throw new RuntimeException(e);
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
347 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
348
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
349 private void updateFlags() {
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
350 DebugConfig config = getConfig();
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
351 if (config == null) {
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
352 meterEnabled = false;
15581
0dc0926cf0d8 added -G:TrackMemUse for measuring memory usage within scopes
Doug Simon <doug.simon@oracle.com>
parents: 14873
diff changeset
353 memUseTrackingEnabled = false;
4394
cf609017d3d4 Fixed warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4392
diff changeset
354 timeEnabled = false;
16144
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
355 verifyEnabled = false;
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
356
16463
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
357 currentDumpLevel = 0;
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
358
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
359 // Be pragmatic: provide a default log stream to prevent a crash if the stream is not
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
360 // set while logging
16405
9bfc4247262f send log output to native tty
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16297
diff changeset
361 output = TTY.cachedOut;
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
362 } else {
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
363 meterEnabled = config.isMeterEnabled();
15581
0dc0926cf0d8 added -G:TrackMemUse for measuring memory usage within scopes
Doug Simon <doug.simon@oracle.com>
parents: 14873
diff changeset
364 memUseTrackingEnabled = config.isMemUseTrackingEnabled();
4394
cf609017d3d4 Fixed warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4392
diff changeset
365 timeEnabled = config.isTimeEnabled();
16144
af9f3a5f091b extended Debug API with DebugVerifyHandlers
Doug Simon <doug.simon@oracle.com>
parents: 15581
diff changeset
366 verifyEnabled = config.isVerifyEnabled();
5302
55bf72fafc41 (preliminary) logging to file (-G:LogFile=asdf.txt)
Lukas Stadler <lukas.stadler@jku.at>
parents: 5134
diff changeset
367 output = config.output();
16463
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
368 currentDumpLevel = config.getDumpLevel();
f1d839174e71 Support for specifying log and dump levels.
Roland Schatz <roland.schatz@oracle.com>
parents: 16405
diff changeset
369 currentLogLevel = config.getLogLevel();
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
370 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
371 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
372
4477
27c5466afd55 Changes to debug framework.
Andreas Woess <andreas.woess@jku.at>
parents: 4437
diff changeset
373 private RuntimeException interceptException(final Throwable e) {
4361
18b52fec79f1 Completed exception interception.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4357
diff changeset
374 final DebugConfig config = getConfig();
18b52fec79f1 Completed exception interception.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4357
diff changeset
375 if (config != null) {
13547
8ea968b6dba9 fix handling of sandboxed debug scopes (don't destroy parent flags)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13197
diff changeset
376 try (DebugScope s = scope("InterceptException", null, e)) {
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
377 return config.interceptException(e);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
378 } catch (Throwable t) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
379 return new RuntimeException("Exception while intercepting exception", t);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13163
diff changeset
380 }
4361
18b52fec79f1 Completed exception interception.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4357
diff changeset
381 }
4477
27c5466afd55 Changes to debug framework.
Andreas Woess <andreas.woess@jku.at>
parents: 4437
diff changeset
382 return null;
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
383 }
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
384
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
385 private DebugValueMap getValueMap() {
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
386 if (valueMap == null) {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
387 computeValueMap(unqualifiedName);
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
388 }
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
389 return valueMap;
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
390 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
391
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
392 long getCurrentValue(int index) {
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
393 return getValueMap().getCurrentValue(index);
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
394 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
395
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
396 void setCurrentValue(int index, long l) {
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
397 getValueMap().setCurrentValue(index, l);
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
398 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
399
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
400 private DebugScope createChild(String newName, Object[] newContext) {
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
401 return new DebugScope(newName, this, false, newContext);
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
402 }
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
403
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
404 public Iterable<Object> getCurrentContext() {
5856
a3e7b8320165 Fix compiler warning.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5307
diff changeset
405 final DebugScope scope = this;
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
406 return new Iterable<Object>() {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
407
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
408 @Override
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
409 public Iterator<Object> iterator() {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
410 return new Iterator<Object>() {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
411
5856
a3e7b8320165 Fix compiler warning.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5307
diff changeset
412 DebugScope currentScope = scope;
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
413 int objectIndex;
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
414
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
415 @Override
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
416 public boolean hasNext() {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
417 selectScope();
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
418 return currentScope != null;
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
419 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
420
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
421 private void selectScope() {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
422 while (currentScope != null && currentScope.context.length <= objectIndex) {
13163
1baa169508f5 made DebugScope be AutoCloseable so that try-with-resource can be used to more cleanly manage scopes
Doug Simon <doug.simon@oracle.com>
parents: 13142
diff changeset
423 currentScope = currentScope.sandbox ? null : currentScope.parent;
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
424 objectIndex = 0;
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
425 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
426 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
427
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
428 @Override
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
429 public Object next() {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
430 selectScope();
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
431 if (currentScope != null) {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
432 return currentScope.context[objectIndex++];
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
433 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
434 throw new IllegalStateException("May only be called if there is a next element.");
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
435 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
436
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
437 @Override
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
438 public void remove() {
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
439 throw new UnsupportedOperationException("This iterator is read only.");
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
440 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
441 };
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
442 }
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4346
diff changeset
443 };
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
444 }
4353
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
445
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
446 public static <T> T call(Callable<T> callable) {
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
447 try {
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
448 return callable.call();
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
449 } catch (Exception e) {
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
450 if (e instanceof RuntimeException) {
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
451 throw (RuntimeException) e;
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
452 } else {
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
453 throw new RuntimeException(e);
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
454 }
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
455 }
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
456 }
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
457
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
458 public void setConfig(DebugConfig newConfig) {
4361
18b52fec79f1 Completed exception interception.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4357
diff changeset
459 configTL.set(newConfig);
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
460 updateFlags();
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
461 }
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
462
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
463 public String getQualifiedName() {
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
464 if (qualifiedName == null) {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
465 if (parent == null) {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
466 qualifiedName = unqualifiedName;
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
467 } else {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
468 qualifiedName = parent.getQualifiedName() + SCOPE_SEP + unqualifiedName;
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
469 }
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
470 }
4357
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
471 return qualifiedName;
719ac1d92a52 More work on debug framework.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4353
diff changeset
472 }
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
473
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
474 public Indent pushIndentLogger() {
21140
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
475 lastUsedIndent = getLastUsedIndent().indent();
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
476 return lastUsedIndent;
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
477 }
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
478
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
479 public IndentImpl getLastUsedIndent() {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
480 if (lastUsedIndent == null) {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
481 if (parent != null) {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
482 lastUsedIndent = new IndentImpl(parent.getLastUsedIndent());
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
483 } else {
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
484 lastUsedIndent = new IndentImpl(null);
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
485 }
7d2f6dd603b0 Make DebugScope lazier and generally reduce overhead of Debug being enabled
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18901
diff changeset
486 }
11382
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
487 return lastUsedIndent;
d7d12ef788ba add logging with indentation in graal.Debug
Erik Eckstein <erik.eckstein@oracle.com>
parents: 10923
diff changeset
488 }
4343
f03c71a0aeb8 Added draft debug classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
489 }