Mercurial > hg > truffle
comparison src/share/vm/runtime/dtraceJSDT.cpp @ 116:018d5b58dd4f
6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
Summary: Initial checkin of JSDT code
Reviewed-by: acorn, sbohne
author | kamg |
---|---|
date | Thu, 17 Apr 2008 22:18:15 -0400 |
parents | |
children | d1605aabd0a1 |
comparison
equal
deleted
inserted
replaced
115:e7a91a357527 | 116:018d5b58dd4f |
---|---|
1 /* | |
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. | |
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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_dtraceJSDT.cpp.incl" | |
27 | |
28 #ifdef HAVE_DTRACE_H | |
29 | |
30 jlong DTraceJSDT::activate( | |
31 jint version, jstring module_name, jint providers_count, | |
32 JVM_DTraceProvider* providers, TRAPS) { | |
33 | |
34 size_t count = 0; | |
35 RegisteredProbes* probes = NULL; | |
36 | |
37 if (!is_supported()) { | |
38 return 0; | |
39 } | |
40 | |
41 assert(module_name != NULL, "valid module name"); | |
42 assert(providers != NULL, "valid provider array"); | |
43 | |
44 for (int i = 0; i < providers_count; ++i) { | |
45 count += providers[i].probe_count; | |
46 } | |
47 probes = new RegisteredProbes(count); | |
48 count = 0; | |
49 | |
50 for (int i = 0; i < providers_count; ++i) { | |
51 assert(providers[i].name != NULL, "valid provider name"); | |
52 assert(providers[i].probe_count == 0 || providers[i].probes != NULL, | |
53 "valid probe count"); | |
54 for (int j = 0; j < providers[i].probe_count; ++j) { | |
55 JVM_DTraceProbe* probe = &(providers[i].probes[j]); | |
56 assert(probe != NULL, "valid probe"); | |
57 assert(probe->method != NULL, "valid method"); | |
58 assert(probe->name != NULL, "valid probe name"); | |
59 assert(probe->function != NULL, "valid probe function spec"); | |
60 methodHandle h_method = | |
61 methodHandle(THREAD, JNIHandles::resolve_jmethod_id(probe->method)); | |
62 nmethod* nm = AdapterHandlerLibrary::create_dtrace_nmethod(h_method); | |
63 h_method()->set_not_compilable(CompLevel_highest_tier); | |
64 h_method()->set_code(h_method, nm); | |
65 probes->nmethod_at_put(count++, nm); | |
66 } | |
67 } | |
68 | |
69 int handle = pd_activate((void*)probes, | |
70 module_name, providers_count, providers); | |
71 if (handle <= 0) { | |
72 delete probes; | |
73 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), | |
74 "Unable to register DTrace probes (internal error)."); | |
75 } | |
76 probes->set_helper_handle(handle); | |
77 return RegisteredProbes::toOpaqueProbes(probes); | |
78 } | |
79 | |
80 jboolean DTraceJSDT::is_probe_enabled(jmethodID method) { | |
81 methodOop m = JNIHandles::resolve_jmethod_id(method); | |
82 return nativeInstruction_at(m->code()->trap_address())->is_dtrace_trap(); | |
83 } | |
84 | |
85 void DTraceJSDT::dispose(OpaqueProbes probes) { | |
86 RegisteredProbes* p = RegisteredProbes::toRegisteredProbes(probes); | |
87 if (probes != -1 && p != NULL) { | |
88 pd_dispose(p->helper_handle()); | |
89 delete p; | |
90 } | |
91 } | |
92 | |
93 jboolean DTraceJSDT::is_supported() { | |
94 return pd_is_supported(); | |
95 } | |
96 | |
97 #else // HAVE_DTRACE_H | |
98 | |
99 jlong DTraceJSDT::activate( | |
100 jint version, jstring module_name, jint providers_count, | |
101 JVM_DTraceProvider* providers, TRAPS) { | |
102 return 0; | |
103 } | |
104 | |
105 jboolean DTraceJSDT::is_probe_enabled(jmethodID method) { | |
106 return false; | |
107 } | |
108 | |
109 void DTraceJSDT::dispose(OpaqueProbes probes) { | |
110 return; | |
111 } | |
112 | |
113 jboolean DTraceJSDT::is_supported() { | |
114 return false; | |
115 } | |
116 | |
117 #endif // ndef HAVE_DTRACE_H |