author | egahlin |
Mon, 08 Jul 2019 18:11:26 +0200 | |
branch | JEP-349-branch |
changeset 57459 | df39f8d8f4d6 |
parent 54786 | ebf733a324d4 |
child 55682 | 70fab3a8ff02 |
child 58678 | 9cf78a70fa4f |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53858 | 2 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/javaClasses.hpp" |
|
27 |
#include "classfile/systemDictionary.hpp" |
|
52876
2d17750d41e7
8214791: Consistently name gc files containing VM operations
tschatzl
parents:
50785
diff
changeset
|
28 |
#include "gc/shared/gcVMOperations.hpp" |
7397 | 29 |
#include "memory/resourceArea.hpp" |
54786 | 30 |
#include "memory/universe.hpp" |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
27880
diff
changeset
|
31 |
#include "oops/oop.inline.hpp" |
49041
44122f767467
8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents:
47216
diff
changeset
|
32 |
#include "oops/typeArrayOop.inline.hpp" |
7397 | 33 |
#include "prims/jvmtiExport.hpp" |
34 |
#include "runtime/arguments.hpp" |
|
49902
3661f31c6df4
8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents:
49860
diff
changeset
|
35 |
#include "runtime/flags/jvmFlag.hpp" |
7397 | 36 |
#include "runtime/globals.hpp" |
49361
1956d0ec092a
8199319: Remove handles.inline.hpp include from reflectionUtils.hpp
stefank
parents:
49041
diff
changeset
|
37 |
#include "runtime/handles.inline.hpp" |
7397 | 38 |
#include "runtime/java.hpp" |
39 |
#include "runtime/javaCalls.hpp" |
|
40 |
#include "runtime/os.hpp" |
|
41 |
#include "services/attachListener.hpp" |
|
11209 | 42 |
#include "services/diagnosticCommand.hpp" |
30764 | 43 |
#include "services/heapDumper.hpp" |
28949
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
44 |
#include "services/writeableFlags.hpp" |
46560
388aa8d67c80
8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents:
46458
diff
changeset
|
45 |
#include "utilities/debug.hpp" |
388aa8d67c80
8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents:
46458
diff
changeset
|
46 |
#include "utilities/formatBuffer.hpp" |
1 | 47 |
|
48 |
volatile bool AttachListener::_initialized; |
|
49 |
||
50 |
// Implementation of "properties" command. |
|
51 |
// |
|
36795
bfd8c074c8ec
8153181: Move sun.misc.VMSupport to an internal package
chegar
parents:
31371
diff
changeset
|
52 |
// Invokes VMSupport.serializePropertiesToByteArray to serialize |
1 | 53 |
// the system properties into a byte array. |
54 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
55 |
static InstanceKlass* load_and_initialize_klass(Symbol* sh, TRAPS) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
56 |
Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL); |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
57 |
InstanceKlass* ik = InstanceKlass::cast(k); |
1 | 58 |
if (ik->should_be_initialized()) { |
59 |
ik->initialize(CHECK_NULL); |
|
60 |
} |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
61 |
return ik; |
1 | 62 |
} |
63 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
64 |
static jint get_properties(AttachOperation* op, outputStream* out, Symbol* serializePropertiesMethod) { |
1 | 65 |
Thread* THREAD = Thread::current(); |
66 |
HandleMark hm; |
|
67 |
||
36795
bfd8c074c8ec
8153181: Move sun.misc.VMSupport to an internal package
chegar
parents:
31371
diff
changeset
|
68 |
// load VMSupport |
bfd8c074c8ec
8153181: Move sun.misc.VMSupport to an internal package
chegar
parents:
31371
diff
changeset
|
69 |
Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport(); |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
70 |
InstanceKlass* k = load_and_initialize_klass(klass, THREAD); |
1 | 71 |
if (HAS_PENDING_EXCEPTION) { |
72 |
java_lang_Throwable::print(PENDING_EXCEPTION, out); |
|
73 |
CLEAR_PENDING_EXCEPTION; |
|
74 |
return JNI_ERR; |
|
75 |
} |
|
76 |
||
77 |
// invoke the serializePropertiesToByteArray method |
|
78 |
JavaValue result(T_OBJECT); |
|
79 |
JavaCallArguments args; |
|
80 |
||
81 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
82 |
Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature(); |
1 | 83 |
JavaCalls::call_static(&result, |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
84 |
k, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
85 |
serializePropertiesMethod, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
86 |
signature, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
87 |
&args, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
88 |
THREAD); |
1 | 89 |
if (HAS_PENDING_EXCEPTION) { |
90 |
java_lang_Throwable::print(PENDING_EXCEPTION, out); |
|
91 |
CLEAR_PENDING_EXCEPTION; |
|
92 |
return JNI_ERR; |
|
93 |
} |
|
94 |
||
95 |
// The result should be a [B |
|
96 |
oop res = (oop)result.get_jobject(); |
|
97 |
assert(res->is_typeArray(), "just checking"); |
|
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
98 |
assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking"); |
1 | 99 |
|
100 |
// copy the bytes to the output stream |
|
101 |
typeArrayOop ba = typeArrayOop(res); |
|
102 |
jbyte* addr = typeArrayOop(res)->byte_at_addr(0); |
|
103 |
out->print_raw((const char*)addr, ba->length()); |
|
104 |
||
105 |
return JNI_OK; |
|
106 |
} |
|
107 |
||
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
108 |
// Implementation of "load" command. |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
109 |
static jint load_agent(AttachOperation* op, outputStream* out) { |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
110 |
// get agent name and options |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
111 |
const char* agent = op->arg(0); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
112 |
const char* absParam = op->arg(1); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
113 |
const char* options = op->arg(2); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
114 |
|
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
115 |
// If loading a java agent then need to ensure that the java.instrument module is loaded |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
116 |
if (strcmp(agent, "instrument") == 0) { |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
117 |
Thread* THREAD = Thread::current(); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
118 |
ResourceMark rm(THREAD); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
119 |
HandleMark hm(THREAD); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
120 |
JavaValue result(T_OBJECT); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
121 |
Handle h_module_name = java_lang_String::create_from_str("java.instrument", THREAD); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
122 |
JavaCalls::call_static(&result, |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
123 |
SystemDictionary::module_Modules_klass(), |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
124 |
vmSymbols::loadModule_name(), |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
125 |
vmSymbols::loadModule_signature(), |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
126 |
h_module_name, |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
127 |
THREAD); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
128 |
if (HAS_PENDING_EXCEPTION) { |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
129 |
java_lang_Throwable::print(PENDING_EXCEPTION, out); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
130 |
CLEAR_PENDING_EXCEPTION; |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
131 |
return JNI_ERR; |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
132 |
} |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
133 |
} |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
134 |
|
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
135 |
return JvmtiExport::load_agent_library(agent, absParam, options, out); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
136 |
} |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
137 |
|
1 | 138 |
// Implementation of "properties" command. |
11441 | 139 |
// See also: PrintSystemPropertiesDCmd class |
1 | 140 |
static jint get_system_properties(AttachOperation* op, outputStream* out) { |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
141 |
return get_properties(op, out, vmSymbols::serializePropertiesToByteArray_name()); |
1 | 142 |
} |
143 |
||
144 |
// Implementation of "agent_properties" command. |
|
145 |
static jint get_agent_properties(AttachOperation* op, outputStream* out) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
146 |
return get_properties(op, out, vmSymbols::serializeAgentPropertiesToByteArray_name()); |
1 | 147 |
} |
148 |
||
149 |
// Implementation of "datadump" command. |
|
150 |
// |
|
151 |
// Raises a SIGBREAK signal so that VM dump threads, does deadlock detection, |
|
152 |
// etc. In theory this command should only post a DataDumpRequest to any |
|
153 |
// JVMTI environment that has enabled this event. However it's useful to |
|
154 |
// trigger the SIGBREAK handler. |
|
155 |
||
156 |
static jint data_dump(AttachOperation* op, outputStream* out) { |
|
157 |
if (!ReduceSignalUsage) { |
|
158 |
AttachListener::pd_data_dump(); |
|
159 |
} else { |
|
160 |
if (JvmtiExport::should_post_data_dump()) { |
|
161 |
JvmtiExport::post_data_dump(); |
|
162 |
} |
|
163 |
} |
|
164 |
return JNI_OK; |
|
165 |
} |
|
166 |
||
167 |
// Implementation of "threaddump" command - essentially a remote ctrl-break |
|
11441 | 168 |
// See also: ThreadDumpDCmd class |
1 | 169 |
// |
170 |
static jint thread_dump(AttachOperation* op, outputStream* out) { |
|
171 |
bool print_concurrent_locks = false; |
|
50785
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
172 |
bool print_extended_info = false; |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
173 |
if (op->arg(0) != NULL) { |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
174 |
for (int i = 0; op->arg(0)[i] != 0; ++i) { |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
175 |
if (op->arg(0)[i] == 'l') { |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
176 |
print_concurrent_locks = true; |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
177 |
} |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
178 |
if (op->arg(0)[i] == 'e') { |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
179 |
print_extended_info = true; |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
180 |
} |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
181 |
} |
1 | 182 |
} |
183 |
||
184 |
// thread stacks |
|
50785
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50217
diff
changeset
|
185 |
VM_PrintThreads op1(out, print_concurrent_locks, print_extended_info); |
1 | 186 |
VMThread::execute(&op1); |
187 |
||
188 |
// JNI global handles |
|
189 |
VM_PrintJNI op2(out); |
|
190 |
VMThread::execute(&op2); |
|
191 |
||
192 |
// Deadlock detection |
|
193 |
VM_FindDeadlocks op3(out); |
|
194 |
VMThread::execute(&op3); |
|
195 |
||
196 |
return JNI_OK; |
|
197 |
} |
|
198 |
||
11209 | 199 |
// A jcmd attach operation request was received, which will now |
200 |
// dispatch to the diagnostic commands used for serviceability functions. |
|
201 |
static jint jcmd(AttachOperation* op, outputStream* out) { |
|
202 |
Thread* THREAD = Thread::current(); |
|
203 |
// All the supplied jcmd arguments are stored as a single |
|
204 |
// string (op->arg(0)). This is parsed by the Dcmd framework. |
|
17296
68557efd8583
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
15432
diff
changeset
|
205 |
DCmd::parse_and_execute(DCmd_Source_AttachAPI, out, op->arg(0), ' ', THREAD); |
11209 | 206 |
if (HAS_PENDING_EXCEPTION) { |
207 |
java_lang_Throwable::print(PENDING_EXCEPTION, out); |
|
11441 | 208 |
out->cr(); |
11209 | 209 |
CLEAR_PENDING_EXCEPTION; |
24833
c55a7c2888f6
8044398: Attach code should propagate errors in Diagnostic Commands as errors
sla
parents:
24424
diff
changeset
|
210 |
return JNI_ERR; |
11209 | 211 |
} |
212 |
return JNI_OK; |
|
213 |
} |
|
214 |
||
1 | 215 |
// Implementation of "dumpheap" command. |
11441 | 216 |
// See also: HeapDumpDCmd class |
1 | 217 |
// |
218 |
// Input arguments :- |
|
219 |
// arg0: Name of the dump file |
|
220 |
// arg1: "-live" or "-all" |
|
221 |
jint dump_heap(AttachOperation* op, outputStream* out) { |
|
222 |
const char* path = op->arg(0); |
|
223 |
if (path == NULL || path[0] == '\0') { |
|
224 |
out->print_cr("No dump file specified"); |
|
225 |
} else { |
|
226 |
bool live_objects_only = true; // default is true to retain the behavior before this change is made |
|
227 |
const char* arg1 = op->arg(1); |
|
228 |
if (arg1 != NULL && (strlen(arg1) > 0)) { |
|
229 |
if (strcmp(arg1, "-all") != 0 && strcmp(arg1, "-live") != 0) { |
|
230 |
out->print_cr("Invalid argument to dumpheap operation: %s", arg1); |
|
231 |
return JNI_ERR; |
|
232 |
} |
|
233 |
live_objects_only = strcmp(arg1, "-live") == 0; |
|
234 |
} |
|
235 |
||
236 |
// Request a full GC before heap dump if live_objects_only = true |
|
237 |
// This helps reduces the amount of unreachable objects in the dump |
|
238 |
// and makes it easier to browse. |
|
239 |
HeapDumper dumper(live_objects_only /* request GC */); |
|
240 |
int res = dumper.dump(op->arg(0)); |
|
241 |
if (res == 0) { |
|
242 |
out->print_cr("Heap dump file created"); |
|
243 |
} else { |
|
244 |
// heap dump failed |
|
245 |
ResourceMark rm; |
|
246 |
char* error = dumper.error_as_C_string(); |
|
247 |
if (error == NULL) { |
|
248 |
out->print_cr("Dump failed - reason unknown"); |
|
249 |
} else { |
|
250 |
out->print_cr("%s", error); |
|
251 |
} |
|
252 |
} |
|
253 |
} |
|
254 |
return JNI_OK; |
|
255 |
} |
|
256 |
||
257 |
// Implementation of "inspectheap" command |
|
11441 | 258 |
// See also: ClassHistogramDCmd class |
1 | 259 |
// |
260 |
// Input arguments :- |
|
54065
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
261 |
// arg0: "-live" or "-all" |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
262 |
// arg1: Name of the dump file or NULL |
1 | 263 |
static jint heap_inspection(AttachOperation* op, outputStream* out) { |
264 |
bool live_objects_only = true; // default is true to retain the behavior before this change is made |
|
53858 | 265 |
outputStream* os = out; // if path not specified or path is NULL, use out |
266 |
fileStream* fs = NULL; |
|
54065
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
267 |
const char* arg0 = op->arg(0); |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
268 |
if (arg0 != NULL && (strlen(arg0) > 0)) { |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
269 |
if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) { |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
270 |
out->print_cr("Invalid argument to inspectheap operation: %s", arg0); |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
271 |
return JNI_ERR; |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
272 |
} |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
273 |
live_objects_only = strcmp(arg0, "-live") == 0; |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
274 |
} |
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
275 |
|
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
276 |
const char* path = op->arg(1); |
53858 | 277 |
if (path != NULL) { |
278 |
if (path[0] == '\0') { |
|
279 |
out->print_cr("No dump file specified"); |
|
280 |
} else { |
|
281 |
// create file |
|
282 |
fs = new (ResourceObj::C_HEAP, mtInternal) fileStream(path); |
|
283 |
if (fs == NULL) { |
|
284 |
out->print_cr("Failed to allocate space for file: %s", path); |
|
285 |
return JNI_ERR; |
|
286 |
} |
|
287 |
os = fs; |
|
288 |
} |
|
289 |
} |
|
54065
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
290 |
|
53858 | 291 |
VM_GC_HeapInspection heapop(os, live_objects_only /* request full gc */); |
1 | 292 |
VMThread::execute(&heapop); |
53858 | 293 |
if (os != NULL && os != out) { |
294 |
out->print_cr("Heap inspection file created: %s", path); |
|
295 |
delete fs; |
|
296 |
} |
|
1 | 297 |
return JNI_OK; |
298 |
} |
|
299 |
||
300 |
// Implementation of "setflag" command |
|
301 |
static jint set_flag(AttachOperation* op, outputStream* out) { |
|
302 |
||
303 |
const char* name = NULL; |
|
304 |
if ((name = op->arg(0)) == NULL) { |
|
305 |
out->print_cr("flag name is missing"); |
|
306 |
return JNI_ERR; |
|
307 |
} |
|
308 |
||
28949
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
309 |
FormatBuffer<80> err_msg("%s", ""); |
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
310 |
|
49902
3661f31c6df4
8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents:
49860
diff
changeset
|
311 |
int ret = WriteableFlags::set_flag(op->arg(0), op->arg(1), JVMFlag::ATTACH_ON_DEMAND, err_msg); |
3661f31c6df4
8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents:
49860
diff
changeset
|
312 |
if (ret != JVMFlag::SUCCESS) { |
3661f31c6df4
8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents:
49860
diff
changeset
|
313 |
if (ret == JVMFlag::NON_WRITABLE) { |
28949
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
314 |
// if the flag is not manageable try to change it through |
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
315 |
// the platform dependent implementation |
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
316 |
return AttachListener::pd_set_flag(op, out); |
1 | 317 |
} else { |
28949
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
318 |
out->print_cr("%s", err_msg.buffer()); |
1 | 319 |
} |
28949
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
320 |
|
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
321 |
return JNI_ERR; |
1 | 322 |
} |
28949
c6f50d62ecef
8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
27880
diff
changeset
|
323 |
return JNI_OK; |
1 | 324 |
} |
325 |
||
326 |
// Implementation of "printflag" command |
|
11441 | 327 |
// See also: PrintVMFlagsDCmd class |
1 | 328 |
static jint print_flag(AttachOperation* op, outputStream* out) { |
329 |
const char* name = NULL; |
|
330 |
if ((name = op->arg(0)) == NULL) { |
|
331 |
out->print_cr("flag name is missing"); |
|
332 |
return JNI_ERR; |
|
333 |
} |
|
49902
3661f31c6df4
8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents:
49860
diff
changeset
|
334 |
JVMFlag* f = JVMFlag::find_flag((char*)name, strlen(name)); |
1 | 335 |
if (f) { |
336 |
f->print_as_flag(out); |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22758
diff
changeset
|
337 |
out->cr(); |
1 | 338 |
} else { |
339 |
out->print_cr("no such flag '%s'", name); |
|
340 |
} |
|
341 |
return JNI_OK; |
|
342 |
} |
|
343 |
||
344 |
// Table to map operation names to functions. |
|
345 |
||
346 |
// names must be of length <= AttachOperation::name_length_max |
|
347 |
static AttachOperationFunctionInfo funcs[] = { |
|
348 |
{ "agentProperties", get_agent_properties }, |
|
349 |
{ "datadump", data_dump }, |
|
350 |
{ "dumpheap", dump_heap }, |
|
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
351 |
{ "load", load_agent }, |
1 | 352 |
{ "properties", get_system_properties }, |
353 |
{ "threaddump", thread_dump }, |
|
354 |
{ "inspectheap", heap_inspection }, |
|
355 |
{ "setflag", set_flag }, |
|
356 |
{ "printflag", print_flag }, |
|
11209 | 357 |
{ "jcmd", jcmd }, |
1 | 358 |
{ NULL, NULL } |
359 |
}; |
|
360 |
||
361 |
||
362 |
||
363 |
// The Attach Listener threads services a queue. It dequeues an operation |
|
364 |
// from the queue, examines the operation name (command), and dispatches |
|
365 |
// to the corresponding function to perform the operation. |
|
366 |
||
367 |
static void attach_listener_thread_entry(JavaThread* thread, TRAPS) { |
|
368 |
os::set_priority(thread, NearMaxPriority); |
|
369 |
||
49737
01960eec4570
8201321: NMT: Unnecessary re-recording thread stack and size when attaching listener to JavaThread
zgu
parents:
49361
diff
changeset
|
370 |
assert(thread == Thread::current(), "Must be"); |
01960eec4570
8201321: NMT: Unnecessary re-recording thread stack and size when attaching listener to JavaThread
zgu
parents:
49361
diff
changeset
|
371 |
assert(thread->stack_base() != NULL && thread->stack_size() > 0, |
01960eec4570
8201321: NMT: Unnecessary re-recording thread stack and size when attaching listener to JavaThread
zgu
parents:
49361
diff
changeset
|
372 |
"Should already be setup"); |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13952
diff
changeset
|
373 |
|
1 | 374 |
if (AttachListener::pd_init() != 0) { |
375 |
return; |
|
376 |
} |
|
377 |
AttachListener::set_initialized(); |
|
378 |
||
379 |
for (;;) { |
|
380 |
AttachOperation* op = AttachListener::dequeue(); |
|
381 |
if (op == NULL) { |
|
382 |
return; // dequeue failed or shutdown |
|
383 |
} |
|
384 |
||
385 |
ResourceMark rm; |
|
386 |
bufferedStream st; |
|
387 |
jint res = JNI_OK; |
|
388 |
||
389 |
// handle special detachall operation |
|
390 |
if (strcmp(op->name(), AttachOperation::detachall_operation_name()) == 0) { |
|
391 |
AttachListener::detachall(); |
|
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
392 |
} else if (!EnableDynamicAgentLoading && strcmp(op->name(), "load") == 0) { |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
393 |
st.print("Dynamic agent loading is not enabled. " |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
394 |
"Use -XX:+EnableDynamicAgentLoading to launch target VM."); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
36795
diff
changeset
|
395 |
res = JNI_ERR; |
1 | 396 |
} else { |
397 |
// find the function to dispatch too |
|
398 |
AttachOperationFunctionInfo* info = NULL; |
|
399 |
for (int i=0; funcs[i].name != NULL; i++) { |
|
400 |
const char* name = funcs[i].name; |
|
401 |
assert(strlen(name) <= AttachOperation::name_length_max, "operation <= name_length_max"); |
|
402 |
if (strcmp(op->name(), name) == 0) { |
|
403 |
info = &(funcs[i]); |
|
404 |
break; |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
// check for platform dependent attach operation |
|
409 |
if (info == NULL) { |
|
410 |
info = AttachListener::pd_find_operation(op->name()); |
|
411 |
} |
|
412 |
||
413 |
if (info != NULL) { |
|
414 |
// dispatch to the function that implements this operation |
|
415 |
res = (info->func)(op, &st); |
|
416 |
} else { |
|
417 |
st.print("Operation %s not recognized!", op->name()); |
|
418 |
res = JNI_ERR; |
|
419 |
} |
|
420 |
} |
|
421 |
||
422 |
// operation complete - send result and output to client |
|
423 |
op->complete(res, &st); |
|
424 |
} |
|
425 |
} |
|
426 |
||
22197
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
427 |
bool AttachListener::has_init_error(TRAPS) { |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
428 |
if (HAS_PENDING_EXCEPTION) { |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
429 |
tty->print_cr("Exception in VM (AttachListener::init) : "); |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
430 |
java_lang_Throwable::print(PENDING_EXCEPTION, tty); |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
431 |
tty->cr(); |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
432 |
|
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
433 |
CLEAR_PENDING_EXCEPTION; |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
434 |
|
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
435 |
return true; |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
436 |
} else { |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
437 |
return false; |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
438 |
} |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
439 |
} |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
440 |
|
1 | 441 |
// Starts the Attach Listener thread |
442 |
void AttachListener::init() { |
|
443 |
EXCEPTION_MARK; |
|
444 |
||
445 |
const char thread_name[] = "Attach Listener"; |
|
22197
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
446 |
Handle string = java_lang_String::create_from_str(thread_name, THREAD); |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
447 |
if (has_init_error(THREAD)) { |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
448 |
return; |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
449 |
} |
1 | 450 |
|
451 |
// Initialize thread_oop to put it into the system threadGroup |
|
452 |
Handle thread_group (THREAD, Universe::system_thread_group()); |
|
50217
843fc56f4686
8203381: Replace InstanceKlass::allocate_instance_handle with JavaCalls::construct_new_instance
iklam
parents:
49902
diff
changeset
|
453 |
Handle thread_oop = JavaCalls::construct_new_instance(SystemDictionary::Thread_klass(), |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
454 |
vmSymbols::threadgroup_string_void_signature(), |
1 | 455 |
thread_group, |
456 |
string, |
|
20067
e0337f5f9f5a
6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents:
18025
diff
changeset
|
457 |
THREAD); |
22197
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
458 |
if (has_init_error(THREAD)) { |
20067
e0337f5f9f5a
6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents:
18025
diff
changeset
|
459 |
return; |
e0337f5f9f5a
6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents:
18025
diff
changeset
|
460 |
} |
1 | 461 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
36795
diff
changeset
|
462 |
Klass* group = SystemDictionary::ThreadGroup_klass(); |
50217
843fc56f4686
8203381: Replace InstanceKlass::allocate_instance_handle with JavaCalls::construct_new_instance
iklam
parents:
49902
diff
changeset
|
463 |
JavaValue result(T_VOID); |
1 | 464 |
JavaCalls::call_special(&result, |
465 |
thread_group, |
|
466 |
group, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
467 |
vmSymbols::add_method_name(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
468 |
vmSymbols::thread_void_signature(), |
50217
843fc56f4686
8203381: Replace InstanceKlass::allocate_instance_handle with JavaCalls::construct_new_instance
iklam
parents:
49902
diff
changeset
|
469 |
thread_oop, |
20067
e0337f5f9f5a
6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents:
18025
diff
changeset
|
470 |
THREAD); |
22197
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
20291
diff
changeset
|
471 |
if (has_init_error(THREAD)) { |
20067
e0337f5f9f5a
6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents:
18025
diff
changeset
|
472 |
return; |
e0337f5f9f5a
6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents:
18025
diff
changeset
|
473 |
} |
1 | 474 |
|
475 |
{ MutexLocker mu(Threads_lock); |
|
476 |
JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry); |
|
477 |
||
478 |
// Check that thread and osthread were created |
|
479 |
if (listener_thread == NULL || listener_thread->osthread() == NULL) { |
|
480 |
vm_exit_during_initialization("java.lang.OutOfMemoryError", |
|
22758
c6b6abb73544
7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents:
22555
diff
changeset
|
481 |
os::native_thread_creation_failed_msg()); |
1 | 482 |
} |
483 |
||
484 |
java_lang_Thread::set_thread(thread_oop(), listener_thread); |
|
485 |
java_lang_Thread::set_daemon(thread_oop()); |
|
486 |
||
487 |
listener_thread->set_threadObj(thread_oop()); |
|
488 |
Threads::add(listener_thread); |
|
489 |
Thread::start(listener_thread); |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
// Performs clean-up tasks on platforms where we can detect that the last |
|
494 |
// client has detached |
|
495 |
void AttachListener::detachall() { |
|
496 |
// call the platform dependent clean-up |
|
497 |
pd_detachall(); |
|
498 |
} |