1 /* 2 * Copyright 1997-2008 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 if (nm == NULL) { 64 delete probes; 65 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), 66 "Unable to register DTrace probes (CodeCache: no room for DTrace nmethods)."); 67 } 68 h_method()->set_not_compilable(CompLevel_highest_tier); 69 h_method()->set_code(h_method, nm); 70 probes->nmethod_at_put(count++, nm); 71 } 72 } 73 74 int handle = pd_activate((void*)probes, 75 module_name, providers_count, providers); 76 if (handle <= 0) { 77 delete probes; 78 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), 79 "Unable to register DTrace probes (internal error)."); 80 } 81 probes->set_helper_handle(handle); 82 return RegisteredProbes::toOpaqueProbes(probes); 83 } 84 85 jboolean DTraceJSDT::is_probe_enabled(jmethodID method) { 86 methodOop m = JNIHandles::resolve_jmethod_id(method); 87 return nativeInstruction_at(m->code()->trap_address())->is_dtrace_trap(); 88 } 89 90 void DTraceJSDT::dispose(OpaqueProbes probes) { 91 RegisteredProbes* p = RegisteredProbes::toRegisteredProbes(probes); 92 if (probes != -1 && p != NULL) { 93 pd_dispose(p->helper_handle()); 94 delete p; 95 } 96 } 97 98 jboolean DTraceJSDT::is_supported() { 99 return pd_is_supported(); 100 } 101 102 #else // HAVE_DTRACE_H 103 104 jlong DTraceJSDT::activate( 105 jint version, jstring module_name, jint providers_count, 106 JVM_DTraceProvider* providers, TRAPS) { 107 return 0; 108 } 109 110 jboolean DTraceJSDT::is_probe_enabled(jmethodID method) { 111 return false; 112 } 113 114 void DTraceJSDT::dispose(OpaqueProbes probes) { 115 return; 116 } 117 118 jboolean DTraceJSDT::is_supported() { 119 return false; 120 } 121 122 #endif // ndef HAVE_DTRACE_H