1 /* 2 * Copyright (c) 1997, 2008, 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 class RegisteredProbes; 26 typedef jlong OpaqueProbes; 27 28 class DTraceJSDT : AllStatic { 29 private: 30 31 static int pd_activate(void* moduleBaseAddress, jstring module, 32 jint providers_count, JVM_DTraceProvider* providers); 33 static void pd_dispose(int handle); 34 static jboolean pd_is_supported(); 35 36 public: 37 38 static OpaqueProbes activate( 39 jint version, jstring module_name, jint providers_count, 40 JVM_DTraceProvider* providers, TRAPS); 41 static jboolean is_probe_enabled(jmethodID method); 42 static void dispose(OpaqueProbes handle); 43 static jboolean is_supported(); 44 }; 45 46 class RegisteredProbes : public CHeapObj { 47 private: 48 nmethod** _nmethods; // all the probe methods 49 size_t _count; // number of probe methods 50 int _helper_handle; // DTrace-assigned identifier 51 52 public: 53 RegisteredProbes(size_t count) { 54 _count = count; 55 _nmethods = NEW_C_HEAP_ARRAY(nmethod*, count); 56 } 57 58 ~RegisteredProbes() { 59 for (size_t i = 0; i < _count; ++i) { 60 // Let the sweeper reclaim it 61 _nmethods[i]->make_not_entrant(); 62 _nmethods[i]->method()->clear_code(); 63 } 64 FREE_C_HEAP_ARRAY(nmethod*, _nmethods); 65 _nmethods = NULL; 66 _count = 0; 67 } 68 69 static RegisteredProbes* toRegisteredProbes(OpaqueProbes p) { 70 return (RegisteredProbes*)(intptr_t)p; 71 } 72 73 static OpaqueProbes toOpaqueProbes(RegisteredProbes* p) { 74 return (OpaqueProbes)(intptr_t)p; 75 } 76 77 void set_helper_handle(int handle) { _helper_handle = handle; } 78 int helper_handle() const { return _helper_handle; } 79 80 nmethod* nmethod_at(size_t i) { 81 assert(i >= 0 && i < _count, "bad nmethod index"); 82 return _nmethods[i]; 83 } 84 85 void nmethod_at_put(size_t i, nmethod* nm) { 86 assert(i >= 0 && i < _count, "bad nmethod index"); 87 _nmethods[i] = nm; 88 } 89 };