1 /* |
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 #include "precompiled.hpp" |
|
26 #include "classfile/javaClasses.hpp" |
|
27 #include "code/codeBlob.hpp" |
|
28 #include "code/nativeInst.hpp" |
|
29 #include "memory/allocation.hpp" |
|
30 #include "prims/jvm.h" |
|
31 #include "runtime/dtraceJSDT.hpp" |
|
32 #include "runtime/jniHandles.hpp" |
|
33 #include "runtime/os.hpp" |
|
34 #include "utilities/exceptions.hpp" |
|
35 #include "utilities/globalDefinitions.hpp" |
|
36 #include "utilities/utf8.hpp" |
|
37 |
|
38 #ifdef HAVE_DTRACE_H |
|
39 |
|
40 jlong DTraceJSDT::activate( |
|
41 jint version, jstring module_name, jint providers_count, |
|
42 JVM_DTraceProvider* providers, TRAPS) { |
|
43 |
|
44 size_t count = 0; |
|
45 RegisteredProbes* probes = NULL; |
|
46 |
|
47 if (!is_supported()) { |
|
48 return 0; |
|
49 } |
|
50 |
|
51 assert(module_name != NULL, "valid module name"); |
|
52 assert(providers != NULL, "valid provider array"); |
|
53 |
|
54 for (int i = 0; i < providers_count; ++i) { |
|
55 count += providers[i].probe_count; |
|
56 } |
|
57 probes = new RegisteredProbes(count); |
|
58 count = 0; |
|
59 |
|
60 for (int i = 0; i < providers_count; ++i) { |
|
61 assert(providers[i].name != NULL, "valid provider name"); |
|
62 assert(providers[i].probe_count == 0 || providers[i].probes != NULL, |
|
63 "valid probe count"); |
|
64 for (int j = 0; j < providers[i].probe_count; ++j) { |
|
65 JVM_DTraceProbe* probe = &(providers[i].probes[j]); |
|
66 assert(probe != NULL, "valid probe"); |
|
67 assert(probe->method != NULL, "valid method"); |
|
68 assert(probe->name != NULL, "valid probe name"); |
|
69 assert(probe->function != NULL, "valid probe function spec"); |
|
70 methodHandle h_method = |
|
71 methodHandle(THREAD, Method::resolve_jmethod_id(probe->method)); |
|
72 nmethod* nm = AdapterHandlerLibrary::create_dtrace_nmethod(h_method); |
|
73 if (nm == NULL) { |
|
74 delete probes; |
|
75 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), |
|
76 "Unable to register DTrace probes (CodeCache: no room for DTrace nmethods)."); |
|
77 } |
|
78 h_method()->set_not_compilable(); |
|
79 h_method()->set_code(h_method, nm); |
|
80 probes->nmethod_at_put(count++, nm); |
|
81 } |
|
82 } |
|
83 |
|
84 int handle = pd_activate((void*)probes, |
|
85 module_name, providers_count, providers); |
|
86 if (handle < 0) { |
|
87 delete probes; |
|
88 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), |
|
89 "Unable to register DTrace probes (internal error)."); |
|
90 } |
|
91 probes->set_helper_handle(handle); |
|
92 return RegisteredProbes::toOpaqueProbes(probes); |
|
93 } |
|
94 |
|
95 jboolean DTraceJSDT::is_probe_enabled(jmethodID method) { |
|
96 Method* m = Method::resolve_jmethod_id(method); |
|
97 return nativeInstruction_at(m->code()->trap_address())->is_dtrace_trap(); |
|
98 } |
|
99 |
|
100 void DTraceJSDT::dispose(OpaqueProbes probes) { |
|
101 RegisteredProbes* p = RegisteredProbes::toRegisteredProbes(probes); |
|
102 if (probes != -1 && p != NULL) { |
|
103 pd_dispose(p->helper_handle()); |
|
104 delete p; |
|
105 } |
|
106 } |
|
107 |
|
108 jboolean DTraceJSDT::is_supported() { |
|
109 return pd_is_supported(); |
|
110 } |
|
111 |
|
112 #else // HAVE_DTRACE_H |
|
113 |
|
114 jlong DTraceJSDT::activate( |
|
115 jint version, jstring module_name, jint providers_count, |
|
116 JVM_DTraceProvider* providers, TRAPS) { |
|
117 return 0; |
|
118 } |
|
119 |
|
120 jboolean DTraceJSDT::is_probe_enabled(jmethodID method) { |
|
121 return false; |
|
122 } |
|
123 |
|
124 void DTraceJSDT::dispose(OpaqueProbes probes) { |
|
125 return; |
|
126 } |
|
127 |
|
128 jboolean DTraceJSDT::is_supported() { |
|
129 return false; |
|
130 } |
|
131 |
|
132 #endif // ndef HAVE_DTRACE_H |
|