author | darcy |
Wed, 25 Apr 2018 22:12:06 -0700 | |
changeset 49895 | 661ef62a6618 |
parent 48373 | f9152f462cbc |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
47517
b5ad886110b3
8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions()
rfield
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
33362 | 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 |
|
48373
f9152f462cbc
8193758: Update copyright headers of files in src tree that are missing Classpath exception
alanb
parents:
47517
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f9152f462cbc
8193758: Update copyright headers of files in src tree that are missing Classpath exception
alanb
parents:
47517
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f9152f462cbc
8193758: Update copyright headers of files in src tree that are missing Classpath exception
alanb
parents:
47517
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
33362 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.internal.jshell.debug; |
|
27 |
||
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
28 |
import java.io.PrintStream; |
33362 | 29 |
import java.util.HashMap; |
30 |
import java.util.Map; |
|
31 |
import jdk.jshell.JShell; |
|
32 |
||
33 |
/** |
|
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
34 |
* This class is used to externally control output messages for debugging the |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
35 |
* implementation of the JShell API. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
36 |
* <p> |
47517
b5ad886110b3
8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions()
rfield
parents:
47216
diff
changeset
|
37 |
* This is not part of the SPI nor API. |
33362 | 38 |
*/ |
39 |
public class InternalDebugControl { |
|
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
40 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
41 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
42 |
* This is a static only class; The constructor should never be called. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
43 |
*/ |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
44 |
private InternalDebugControl() { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
45 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
46 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
47 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
48 |
* General debugging. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
49 |
*/ |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
50 |
public static final int DBG_GEN = 0b0000001; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
51 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
52 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
53 |
* File manager debuging. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
54 |
*/ |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
55 |
public static final int DBG_FMGR = 0b0000010; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
56 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
57 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
58 |
* Completion analysis debugging. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
59 |
*/ |
33362 | 60 |
public static final int DBG_COMPA = 0b0000100; |
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
61 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
62 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
63 |
* Dependency debugging. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
64 |
*/ |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
65 |
public static final int DBG_DEP = 0b0001000; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
66 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
67 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
68 |
* Event debugging. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
69 |
*/ |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
70 |
public static final int DBG_EVNT = 0b0010000; |
33362 | 71 |
|
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
38535
diff
changeset
|
72 |
/** |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
38535
diff
changeset
|
73 |
* Event debugging. |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
38535
diff
changeset
|
74 |
*/ |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
38535
diff
changeset
|
75 |
public static final int DBG_WRAP = 0b0100000; |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
38535
diff
changeset
|
76 |
|
33362 | 77 |
private static Map<JShell, Integer> debugMap = null; |
78 |
||
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
79 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
80 |
* Sets which debug flags are enabled for a given JShell instance. The flags |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
81 |
* are or'ed bits as defined in {@code DBG_*}. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
82 |
* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
83 |
* @param state the JShell instance |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
84 |
* @param flags the or'ed debug bits |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
85 |
*/ |
33362 | 86 |
public static void setDebugFlags(JShell state, int flags) { |
87 |
if (debugMap == null) { |
|
88 |
debugMap = new HashMap<>(); |
|
89 |
} |
|
90 |
debugMap.put(state, flags); |
|
91 |
} |
|
92 |
||
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
93 |
/** |
43757 | 94 |
* Release a JShell instance. |
95 |
* |
|
96 |
* @param state the JShell instance |
|
97 |
*/ |
|
98 |
public static void release(JShell state) { |
|
99 |
if (debugMap != null) { |
|
100 |
debugMap.remove(state); |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
/** |
|
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
105 |
* Tests if any of the specified debug flags are enabled. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
106 |
* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
107 |
* @param state the JShell instance |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
108 |
* @param flag the {@code DBG_*} bits to check |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
109 |
* @return true if any of the flags are enabled |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
110 |
*/ |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
111 |
public static boolean isDebugEnabled(JShell state, int flag) { |
33362 | 112 |
if (debugMap == null) { |
113 |
return false; |
|
114 |
} |
|
115 |
Integer flags = debugMap.get(state); |
|
116 |
if (flags == null) { |
|
117 |
return false; |
|
118 |
} |
|
119 |
return (flags & flag) != 0; |
|
120 |
} |
|
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
121 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
122 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
123 |
* Displays debug info if the specified debug flags are enabled. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
124 |
* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
125 |
* @param state the current JShell instance |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
126 |
* @param err the {@code PrintStream} to report on |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
127 |
* @param flags {@code DBG_*} flag bits to check |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
128 |
* @param format format string for the output |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
129 |
* @param args args for the format string |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
130 |
*/ |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
131 |
public static void debug(JShell state, PrintStream err, int flags, String format, Object... args) { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
132 |
if (isDebugEnabled(state, flags)) { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
133 |
err.printf(format, args); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
134 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
135 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
136 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
137 |
/** |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
138 |
* Displays a fatal exception as debug info. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
139 |
* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
140 |
* @param state the current JShell instance |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
141 |
* @param err the {@code PrintStream} to report on |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
142 |
* @param ex the fatal Exception |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
143 |
* @param where additional context |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
144 |
*/ |
47517
b5ad886110b3
8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions()
rfield
parents:
47216
diff
changeset
|
145 |
public static void debug(JShell state, PrintStream err, Throwable ex, String where) { |
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
146 |
if (isDebugEnabled(state, 0xFFFFFFFF)) { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
147 |
err.printf("Fatal error: %s: %s\n", where, ex.getMessage()); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
148 |
ex.printStackTrace(err); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
149 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
33362
diff
changeset
|
150 |
} |
33362 | 151 |
} |