annotate src/share/vm/services/attachListener.cpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 52b4284cb496 2545e461115b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17648
diff changeset
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1142
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1142
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1142
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/javaClasses.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "gc_implementation/shared/vmGCOperations.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "prims/jvmtiExport.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "runtime/arguments.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/globals.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "runtime/java.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "runtime/javaCalls.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 #include "services/attachListener.hpp"
4133
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
37 #include "services/diagnosticCommand.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 #include "services/heapDumper.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 volatile bool AttachListener::_initialized;
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Implementation of "properties" command.
a61af66fc99e Initial load
duke
parents:
diff changeset
43 //
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Invokes sun.misc.VMSupport.serializePropertiesToByteArray to serialize
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // the system properties into a byte array.
a61af66fc99e Initial load
duke
parents:
diff changeset
46
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
47 static Klass* load_and_initialize_klass(Symbol* sh, TRAPS) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
48 Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49 instanceKlassHandle ik (THREAD, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 if (ik->should_be_initialized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 ik->initialize(CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53 return ik();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
56 static jint get_properties(AttachOperation* op, outputStream* out, Symbol* serializePropertiesMethod) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
57 Thread* THREAD = Thread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // load sun.misc.VMSupport
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
61 Symbol* klass = vmSymbols::sun_misc_VMSupport();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
62 Klass* k = load_and_initialize_klass(klass, THREAD);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63 if (HAS_PENDING_EXCEPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 java_lang_Throwable::print(PENDING_EXCEPTION, out);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 CLEAR_PENDING_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 instanceKlassHandle ik(THREAD, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // invoke the serializePropertiesToByteArray method
a61af66fc99e Initial load
duke
parents:
diff changeset
71 JavaValue result(T_OBJECT);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 JavaCallArguments args;
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
75 Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 JavaCalls::call_static(&result,
a61af66fc99e Initial load
duke
parents:
diff changeset
77 ik,
a61af66fc99e Initial load
duke
parents:
diff changeset
78 serializePropertiesMethod,
a61af66fc99e Initial load
duke
parents:
diff changeset
79 signature,
a61af66fc99e Initial load
duke
parents:
diff changeset
80 &args,
a61af66fc99e Initial load
duke
parents:
diff changeset
81 THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (HAS_PENDING_EXCEPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 java_lang_Throwable::print(PENDING_EXCEPTION, out);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 CLEAR_PENDING_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // The result should be a [B
a61af66fc99e Initial load
duke
parents:
diff changeset
89 oop res = (oop)result.get_jobject();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 assert(res->is_typeArray(), "just checking");
6831
d8ce2825b193 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 6725
diff changeset
91 assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // copy the bytes to the output stream
a61af66fc99e Initial load
duke
parents:
diff changeset
94 typeArrayOop ba = typeArrayOop(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 out->print_raw((const char*)addr, ba->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return JNI_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Implementation of "properties" command.
4773
4f25538b54c9 7120511: Add diagnostic commands
fparain
parents: 4133
diff changeset
102 // See also: PrintSystemPropertiesDCmd class
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 static jint get_system_properties(AttachOperation* op, outputStream* out) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
104 return get_properties(op, out, vmSymbols::serializePropertiesToByteArray_name());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Implementation of "agent_properties" command.
a61af66fc99e Initial load
duke
parents:
diff changeset
108 static jint get_agent_properties(AttachOperation* op, outputStream* out) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
109 return get_properties(op, out, vmSymbols::serializeAgentPropertiesToByteArray_name());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // Implementation of "datadump" command.
a61af66fc99e Initial load
duke
parents:
diff changeset
113 //
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // Raises a SIGBREAK signal so that VM dump threads, does deadlock detection,
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // etc. In theory this command should only post a DataDumpRequest to any
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // JVMTI environment that has enabled this event. However it's useful to
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // trigger the SIGBREAK handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 static jint data_dump(AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (!ReduceSignalUsage) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 AttachListener::pd_data_dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (JvmtiExport::should_post_data_dump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 JvmtiExport::post_data_dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return JNI_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Implementation of "threaddump" command - essentially a remote ctrl-break
4773
4f25538b54c9 7120511: Add diagnostic commands
fparain
parents: 4133
diff changeset
131 // See also: ThreadDumpDCmd class
0
a61af66fc99e Initial load
duke
parents:
diff changeset
132 //
a61af66fc99e Initial load
duke
parents:
diff changeset
133 static jint thread_dump(AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 bool print_concurrent_locks = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 if (op->arg(0) != NULL && strcmp(op->arg(0), "-l") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 print_concurrent_locks = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // thread stacks
a61af66fc99e Initial load
duke
parents:
diff changeset
140 VM_PrintThreads op1(out, print_concurrent_locks);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 VMThread::execute(&op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // JNI global handles
a61af66fc99e Initial load
duke
parents:
diff changeset
144 VM_PrintJNI op2(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 VMThread::execute(&op2);
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // Deadlock detection
a61af66fc99e Initial load
duke
parents:
diff changeset
148 VM_FindDeadlocks op3(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 VMThread::execute(&op3);
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return JNI_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
4133
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
154 // A jcmd attach operation request was received, which will now
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
155 // dispatch to the diagnostic commands used for serviceability functions.
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
156 static jint jcmd(AttachOperation* op, outputStream* out) {
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
157 Thread* THREAD = Thread::current();
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
158 // All the supplied jcmd arguments are stored as a single
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
159 // string (op->arg(0)). This is parsed by the Dcmd framework.
10215
31a4e55f8c9d 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 7951
diff changeset
160 DCmd::parse_and_execute(DCmd_Source_AttachAPI, out, op->arg(0), ' ', THREAD);
4133
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
161 if (HAS_PENDING_EXCEPTION) {
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
162 java_lang_Throwable::print(PENDING_EXCEPTION, out);
4773
4f25538b54c9 7120511: Add diagnostic commands
fparain
parents: 4133
diff changeset
163 out->cr();
4133
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
164 CLEAR_PENDING_EXCEPTION;
20414
2545e461115b 8044398: Attach code should propagate errors in Diagnostic Commands as errors
sla
parents: 17937
diff changeset
165 return JNI_ERR;
4133
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
166 }
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
167 return JNI_OK;
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
168 }
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
169
0
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Implementation of "dumpheap" command.
4773
4f25538b54c9 7120511: Add diagnostic commands
fparain
parents: 4133
diff changeset
171 // See also: HeapDumpDCmd class
0
a61af66fc99e Initial load
duke
parents:
diff changeset
172 //
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Input arguments :-
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // arg0: Name of the dump file
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // arg1: "-live" or "-all"
a61af66fc99e Initial load
duke
parents:
diff changeset
176 jint dump_heap(AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 const char* path = op->arg(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (path == NULL || path[0] == '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 out->print_cr("No dump file specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
180 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 bool live_objects_only = true; // default is true to retain the behavior before this change is made
a61af66fc99e Initial load
duke
parents:
diff changeset
182 const char* arg1 = op->arg(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (arg1 != NULL && (strlen(arg1) > 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (strcmp(arg1, "-all") != 0 && strcmp(arg1, "-live") != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 out->print_cr("Invalid argument to dumpheap operation: %s", arg1);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 live_objects_only = strcmp(arg1, "-live") == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // Request a full GC before heap dump if live_objects_only = true
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // This helps reduces the amount of unreachable objects in the dump
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // and makes it easier to browse.
a61af66fc99e Initial load
duke
parents:
diff changeset
194 HeapDumper dumper(live_objects_only /* request GC */);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 int res = dumper.dump(op->arg(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
196 if (res == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 out->print_cr("Heap dump file created");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // heap dump failed
a61af66fc99e Initial load
duke
parents:
diff changeset
200 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 char* error = dumper.error_as_C_string();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 if (error == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 out->print_cr("Dump failed - reason unknown");
a61af66fc99e Initial load
duke
parents:
diff changeset
204 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 out->print_cr("%s", error);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return JNI_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // Implementation of "inspectheap" command
4773
4f25538b54c9 7120511: Add diagnostic commands
fparain
parents: 4133
diff changeset
213 // See also: ClassHistogramDCmd class
0
a61af66fc99e Initial load
duke
parents:
diff changeset
214 //
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Input arguments :-
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // arg0: "-live" or "-all"
a61af66fc99e Initial load
duke
parents:
diff changeset
217 static jint heap_inspection(AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 bool live_objects_only = true; // default is true to retain the behavior before this change is made
a61af66fc99e Initial load
duke
parents:
diff changeset
219 const char* arg0 = op->arg(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 if (arg0 != NULL && (strlen(arg0) > 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 live_objects_only = strcmp(arg0, "-live") == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10215
diff changeset
227 VM_GC_HeapInspection heapop(out, live_objects_only /* request full gc */);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
228 VMThread::execute(&heapop);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 return JNI_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // set a boolean global flag using value from AttachOperation
a61af66fc99e Initial load
duke
parents:
diff changeset
233 static jint set_bool_flag(const char* name, AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 bool value = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 const char* arg1;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 if ((arg1 = op->arg(1)) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 int tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 int n = sscanf(arg1, "%d", &tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
239 if (n != 1) {
1067
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
240 out->print_cr("flag value must be a boolean (1 or 0)");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
241 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243 value = (tmp != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
12322
72b7e96c1922 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 10405
diff changeset
245 bool res = CommandLineFlags::boolAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (! res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 out->print_cr("setting flag %s failed", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 return res? JNI_OK : JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // set a intx global flag using value from AttachOperation
a61af66fc99e Initial load
duke
parents:
diff changeset
253 static jint set_intx_flag(const char* name, AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 intx value;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 const char* arg1;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 if ((arg1 = op->arg(1)) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 int n = sscanf(arg1, INTX_FORMAT, &value);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (n != 1) {
1067
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
259 out->print_cr("flag value must be an integer");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
260 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
12322
72b7e96c1922 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 10405
diff changeset
263 bool res = CommandLineFlags::intxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
264 if (! res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 out->print_cr("setting flag %s failed", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return res? JNI_OK : JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // set a uintx global flag using value from AttachOperation
a61af66fc99e Initial load
duke
parents:
diff changeset
272 static jint set_uintx_flag(const char* name, AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 uintx value;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 const char* arg1;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if ((arg1 = op->arg(1)) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 int n = sscanf(arg1, UINTX_FORMAT, &value);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 if (n != 1) {
1067
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
278 out->print_cr("flag value must be an unsigned integer");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
279 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
17648
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
282
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
283 if (strncmp(name, "MaxHeapFreeRatio", 17) == 0) {
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17648
diff changeset
284 FormatBuffer<80> err_msg("%s", "");
17648
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
285 if (!Arguments::verify_MaxHeapFreeRatio(err_msg, value)) {
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17648
diff changeset
286 out->print_cr("%s", err_msg.buffer());
17648
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
287 return JNI_ERR;
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
288 }
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
289 } else if (strncmp(name, "MinHeapFreeRatio", 17) == 0) {
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17648
diff changeset
290 FormatBuffer<80> err_msg("%s", "");
17648
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
291 if (!Arguments::verify_MinHeapFreeRatio(err_msg, value)) {
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17648
diff changeset
292 out->print_cr("%s", err_msg.buffer());
17648
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
293 return JNI_ERR;
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
294 }
a034dc5e910b 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 12325
diff changeset
295 }
12322
72b7e96c1922 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 10405
diff changeset
296 bool res = CommandLineFlags::uintxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
1067
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
297 if (! res) {
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
298 out->print_cr("setting flag %s failed", name);
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
299 }
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
300
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
301 return res? JNI_OK : JNI_ERR;
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
302 }
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
303
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
304 // set a uint64_t global flag using value from AttachOperation
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
305 static jint set_uint64_t_flag(const char* name, AttachOperation* op, outputStream* out) {
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
306 uint64_t value;
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
307 const char* arg1;
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
308 if ((arg1 = op->arg(1)) != NULL) {
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
309 int n = sscanf(arg1, UINT64_FORMAT, &value);
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
310 if (n != 1) {
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
311 out->print_cr("flag value must be an unsigned 64-bit integer");
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
312 return JNI_ERR;
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
313 }
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
314 }
12322
72b7e96c1922 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 10405
diff changeset
315 bool res = CommandLineFlags::uint64_tAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
316 if (! res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 out->print_cr("setting flag %s failed", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 return res? JNI_OK : JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // set a string global flag using value from AttachOperation
a61af66fc99e Initial load
duke
parents:
diff changeset
324 static jint set_ccstr_flag(const char* name, AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 const char* value;
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if ((value = op->arg(1)) == NULL) {
1067
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
327 out->print_cr("flag value must be a string");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
328 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
12322
72b7e96c1922 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 10405
diff changeset
330 bool res = CommandLineFlags::ccstrAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (res) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 4773
diff changeset
332 FREE_C_HEAP_ARRAY(char, value, mtInternal);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
333 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 out->print_cr("setting flag %s failed", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336
a61af66fc99e Initial load
duke
parents:
diff changeset
337 return res? JNI_OK : JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // Implementation of "setflag" command
a61af66fc99e Initial load
duke
parents:
diff changeset
341 static jint set_flag(AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 const char* name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if ((name = op->arg(0)) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 out->print_cr("flag name is missing");
a61af66fc99e Initial load
duke
parents:
diff changeset
346 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 Flag* f = Flag::find_flag((char*)name, strlen(name));
a61af66fc99e Initial load
duke
parents:
diff changeset
350 if (f && f->is_external() && f->is_writeable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (f->is_bool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 return set_bool_flag(name, op, out);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 } else if (f->is_intx()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 return set_intx_flag(name, op, out);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 } else if (f->is_uintx()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 return set_uintx_flag(name, op, out);
1067
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
357 } else if (f->is_uint64_t()) {
ba7ea42fc66e 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 615
diff changeset
358 return set_uint64_t_flag(name, op, out);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
359 } else if (f->is_ccstr()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
360 return set_ccstr_flag(name, op, out);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 return AttachListener::pd_set_flag(op, out);
a61af66fc99e Initial load
duke
parents:
diff changeset
367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // Implementation of "printflag" command
4773
4f25538b54c9 7120511: Add diagnostic commands
fparain
parents: 4133
diff changeset
371 // See also: PrintVMFlagsDCmd class
0
a61af66fc99e Initial load
duke
parents:
diff changeset
372 static jint print_flag(AttachOperation* op, outputStream* out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 const char* name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 if ((name = op->arg(0)) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 out->print_cr("flag name is missing");
a61af66fc99e Initial load
duke
parents:
diff changeset
376 return JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378 Flag* f = Flag::find_flag((char*)name, strlen(name));
a61af66fc99e Initial load
duke
parents:
diff changeset
379 if (f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 f->print_as_flag(out);
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17648
diff changeset
381 out->cr();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
382 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 out->print_cr("no such flag '%s'", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385 return JNI_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // Table to map operation names to functions.
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 // names must be of length <= AttachOperation::name_length_max
a61af66fc99e Initial load
duke
parents:
diff changeset
391 static AttachOperationFunctionInfo funcs[] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 { "agentProperties", get_agent_properties },
a61af66fc99e Initial load
duke
parents:
diff changeset
393 { "datadump", data_dump },
a61af66fc99e Initial load
duke
parents:
diff changeset
394 { "dumpheap", dump_heap },
a61af66fc99e Initial load
duke
parents:
diff changeset
395 { "load", JvmtiExport::load_agent_library },
a61af66fc99e Initial load
duke
parents:
diff changeset
396 { "properties", get_system_properties },
a61af66fc99e Initial load
duke
parents:
diff changeset
397 { "threaddump", thread_dump },
a61af66fc99e Initial load
duke
parents:
diff changeset
398 { "inspectheap", heap_inspection },
a61af66fc99e Initial load
duke
parents:
diff changeset
399 { "setflag", set_flag },
a61af66fc99e Initial load
duke
parents:
diff changeset
400 { "printflag", print_flag },
4133
3b688d6ff3d0 7104647: Adding a diagnostic command framework
fparain
parents: 2426
diff changeset
401 { "jcmd", jcmd },
0
a61af66fc99e Initial load
duke
parents:
diff changeset
402 { NULL, NULL }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 };
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // The Attach Listener threads services a queue. It dequeues an operation
a61af66fc99e Initial load
duke
parents:
diff changeset
408 // from the queue, examines the operation name (command), and dispatches
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // to the corresponding function to perform the operation.
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 static void attach_listener_thread_entry(JavaThread* thread, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 os::set_priority(thread, NearMaxPriority);
a61af66fc99e Initial load
duke
parents:
diff changeset
413
6882
716c64bda5ba 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 6831
diff changeset
414 thread->record_stack_base_and_size();
716c64bda5ba 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 6831
diff changeset
415
0
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if (AttachListener::pd_init() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419 AttachListener::set_initialized();
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 for (;;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 AttachOperation* op = AttachListener::dequeue();
a61af66fc99e Initial load
duke
parents:
diff changeset
423 if (op == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
424 return; // dequeue failed or shutdown
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426
a61af66fc99e Initial load
duke
parents:
diff changeset
427 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 bufferedStream st;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 jint res = JNI_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 // handle special detachall operation
a61af66fc99e Initial load
duke
parents:
diff changeset
432 if (strcmp(op->name(), AttachOperation::detachall_operation_name()) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 AttachListener::detachall();
a61af66fc99e Initial load
duke
parents:
diff changeset
434 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // find the function to dispatch too
a61af66fc99e Initial load
duke
parents:
diff changeset
436 AttachOperationFunctionInfo* info = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
437 for (int i=0; funcs[i].name != NULL; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 const char* name = funcs[i].name;
a61af66fc99e Initial load
duke
parents:
diff changeset
439 assert(strlen(name) <= AttachOperation::name_length_max, "operation <= name_length_max");
a61af66fc99e Initial load
duke
parents:
diff changeset
440 if (strcmp(op->name(), name) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 info = &(funcs[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // check for platform dependent attach operation
a61af66fc99e Initial load
duke
parents:
diff changeset
447 if (info == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
448 info = AttachListener::pd_find_operation(op->name());
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 if (info != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // dispatch to the function that implements this operation
a61af66fc99e Initial load
duke
parents:
diff changeset
453 res = (info->func)(op, &st);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 st.print("Operation %s not recognized!", op->name());
a61af66fc99e Initial load
duke
parents:
diff changeset
456 res = JNI_ERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 // operation complete - send result and output to client
a61af66fc99e Initial load
duke
parents:
diff changeset
461 op->complete(res, &st);
a61af66fc99e Initial load
duke
parents:
diff changeset
462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
464
a61af66fc99e Initial load
duke
parents:
diff changeset
465 // Starts the Attach Listener thread
a61af66fc99e Initial load
duke
parents:
diff changeset
466 void AttachListener::init() {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 EXCEPTION_MARK;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
468 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
469 instanceKlassHandle klass (THREAD, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
470 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 const char thread_name[] = "Attach Listener";
a61af66fc99e Initial load
duke
parents:
diff changeset
473 Handle string = java_lang_String::create_from_str(thread_name, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
474
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // Initialize thread_oop to put it into the system threadGroup
a61af66fc99e Initial load
duke
parents:
diff changeset
476 Handle thread_group (THREAD, Universe::system_thread_group());
a61af66fc99e Initial load
duke
parents:
diff changeset
477 JavaValue result(T_VOID);
a61af66fc99e Initial load
duke
parents:
diff changeset
478 JavaCalls::call_special(&result, thread_oop,
a61af66fc99e Initial load
duke
parents:
diff changeset
479 klass,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
480 vmSymbols::object_initializer_name(),
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
481 vmSymbols::threadgroup_string_void_signature(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
482 thread_group,
a61af66fc99e Initial load
duke
parents:
diff changeset
483 string,
12289
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
484 THREAD);
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
485
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
486 if (HAS_PENDING_EXCEPTION) {
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
487 tty->print_cr("Exception in VM (AttachListener::init) : ");
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
488 java_lang_Throwable::print(PENDING_EXCEPTION, tty);
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
489 tty->cr();
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
490
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
491 CLEAR_PENDING_EXCEPTION;
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
492
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
493 return;
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
494 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
495
1142
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 1067
diff changeset
496 KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
497 JavaCalls::call_special(&result,
a61af66fc99e Initial load
duke
parents:
diff changeset
498 thread_group,
a61af66fc99e Initial load
duke
parents:
diff changeset
499 group,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
500 vmSymbols::add_method_name(),
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
501 vmSymbols::thread_void_signature(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
502 thread_oop, // ARG 1
12289
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
503 THREAD);
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
504
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
505 if (HAS_PENDING_EXCEPTION) {
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
506 tty->print_cr("Exception in VM (AttachListener::init) : ");
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
507 java_lang_Throwable::print(PENDING_EXCEPTION, tty);
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
508 tty->cr();
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
509
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
510 CLEAR_PENDING_EXCEPTION;
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
511
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
512 return;
8ddc26f62476 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 10405
diff changeset
513 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515 { MutexLocker mu(Threads_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // Check that thread and osthread were created
a61af66fc99e Initial load
duke
parents:
diff changeset
519 if (listener_thread == NULL || listener_thread->osthread() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 vm_exit_during_initialization("java.lang.OutOfMemoryError",
a61af66fc99e Initial load
duke
parents:
diff changeset
521 "unable to create new native thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
522 }
a61af66fc99e Initial load
duke
parents:
diff changeset
523
a61af66fc99e Initial load
duke
parents:
diff changeset
524 java_lang_Thread::set_thread(thread_oop(), listener_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
525 java_lang_Thread::set_daemon(thread_oop());
a61af66fc99e Initial load
duke
parents:
diff changeset
526
a61af66fc99e Initial load
duke
parents:
diff changeset
527 listener_thread->set_threadObj(thread_oop());
a61af66fc99e Initial load
duke
parents:
diff changeset
528 Threads::add(listener_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
529 Thread::start(listener_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // Performs clean-up tasks on platforms where we can detect that the last
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // client has detached
a61af66fc99e Initial load
duke
parents:
diff changeset
535 void AttachListener::detachall() {
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // call the platform dependent clean-up
a61af66fc99e Initial load
duke
parents:
diff changeset
537 pd_detachall();
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }