Mon, 18 Mar 2013 13:19:06 +0100
8008555: Debugging code in compiled method sometimes leaks memory
Summary: support for strings that have same life-time as code that uses them.
Reviewed-by: kvn, twisti
kamg@551 | 1 | /* |
mikael@4153 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
kamg@551 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
kamg@551 | 4 | * |
kamg@551 | 5 | * This code is free software; you can redistribute it and/or modify it |
kamg@551 | 6 | * under the terms of the GNU General Public License version 2 only, as |
kamg@551 | 7 | * published by the Free Software Foundation. |
kamg@551 | 8 | * |
kamg@551 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
kamg@551 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
kamg@551 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
kamg@551 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
kamg@551 | 13 | * accompanied this code). |
kamg@551 | 14 | * |
kamg@551 | 15 | * You should have received a copy of the GNU General Public License version |
kamg@551 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
kamg@551 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
kamg@551 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
kamg@551 | 22 | * |
kamg@551 | 23 | */ |
kamg@551 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_RUNTIME_DTRACEJSDT_HPP |
stefank@2314 | 26 | #define SHARE_VM_RUNTIME_DTRACEJSDT_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "code/nmethod.hpp" |
stefank@2314 | 29 | #ifdef TARGET_ARCH_x86 |
stefank@2314 | 30 | # include "nativeInst_x86.hpp" |
stefank@2314 | 31 | #endif |
stefank@2314 | 32 | #ifdef TARGET_ARCH_sparc |
stefank@2314 | 33 | # include "nativeInst_sparc.hpp" |
stefank@2314 | 34 | #endif |
stefank@2314 | 35 | #ifdef TARGET_ARCH_zero |
stefank@2314 | 36 | # include "nativeInst_zero.hpp" |
stefank@2314 | 37 | #endif |
bobv@2508 | 38 | #ifdef TARGET_ARCH_arm |
bobv@2508 | 39 | # include "nativeInst_arm.hpp" |
bobv@2508 | 40 | #endif |
bobv@2508 | 41 | #ifdef TARGET_ARCH_ppc |
bobv@2508 | 42 | # include "nativeInst_ppc.hpp" |
bobv@2508 | 43 | #endif |
stefank@2314 | 44 | |
kamg@551 | 45 | class RegisteredProbes; |
kamg@551 | 46 | typedef jlong OpaqueProbes; |
kamg@551 | 47 | |
kamg@551 | 48 | class DTraceJSDT : AllStatic { |
kamg@551 | 49 | private: |
kamg@551 | 50 | |
kamg@551 | 51 | static int pd_activate(void* moduleBaseAddress, jstring module, |
kamg@551 | 52 | jint providers_count, JVM_DTraceProvider* providers); |
kamg@551 | 53 | static void pd_dispose(int handle); |
kamg@551 | 54 | static jboolean pd_is_supported(); |
kamg@551 | 55 | |
kamg@551 | 56 | public: |
kamg@551 | 57 | |
kamg@551 | 58 | static OpaqueProbes activate( |
kamg@551 | 59 | jint version, jstring module_name, jint providers_count, |
kamg@551 | 60 | JVM_DTraceProvider* providers, TRAPS); |
kamg@551 | 61 | static jboolean is_probe_enabled(jmethodID method); |
kamg@551 | 62 | static void dispose(OpaqueProbes handle); |
kamg@551 | 63 | static jboolean is_supported(); |
kamg@551 | 64 | }; |
kamg@551 | 65 | |
zgu@3900 | 66 | class RegisteredProbes : public CHeapObj<mtInternal> { |
kamg@551 | 67 | private: |
kamg@551 | 68 | nmethod** _nmethods; // all the probe methods |
kamg@551 | 69 | size_t _count; // number of probe methods |
kamg@551 | 70 | int _helper_handle; // DTrace-assigned identifier |
kamg@551 | 71 | |
kamg@551 | 72 | public: |
kamg@551 | 73 | RegisteredProbes(size_t count) { |
kamg@551 | 74 | _count = count; |
zgu@3900 | 75 | _nmethods = NEW_C_HEAP_ARRAY(nmethod*, count, mtInternal); |
kamg@551 | 76 | } |
kamg@551 | 77 | |
kamg@551 | 78 | ~RegisteredProbes() { |
kamg@551 | 79 | for (size_t i = 0; i < _count; ++i) { |
kamg@551 | 80 | // Let the sweeper reclaim it |
kamg@551 | 81 | _nmethods[i]->make_not_entrant(); |
kamg@551 | 82 | _nmethods[i]->method()->clear_code(); |
kamg@551 | 83 | } |
zgu@3900 | 84 | FREE_C_HEAP_ARRAY(nmethod*, _nmethods, mtInternal); |
kamg@551 | 85 | _nmethods = NULL; |
kamg@551 | 86 | _count = 0; |
kamg@551 | 87 | } |
kamg@551 | 88 | |
kamg@551 | 89 | static RegisteredProbes* toRegisteredProbes(OpaqueProbes p) { |
kamg@551 | 90 | return (RegisteredProbes*)(intptr_t)p; |
kamg@551 | 91 | } |
kamg@551 | 92 | |
kamg@551 | 93 | static OpaqueProbes toOpaqueProbes(RegisteredProbes* p) { |
kamg@551 | 94 | return (OpaqueProbes)(intptr_t)p; |
kamg@551 | 95 | } |
kamg@551 | 96 | |
kamg@551 | 97 | void set_helper_handle(int handle) { _helper_handle = handle; } |
kamg@551 | 98 | int helper_handle() const { return _helper_handle; } |
kamg@551 | 99 | |
kamg@551 | 100 | nmethod* nmethod_at(size_t i) { |
kamg@551 | 101 | assert(i >= 0 && i < _count, "bad nmethod index"); |
kamg@551 | 102 | return _nmethods[i]; |
kamg@551 | 103 | } |
kamg@551 | 104 | |
kamg@551 | 105 | void nmethod_at_put(size_t i, nmethod* nm) { |
kamg@551 | 106 | assert(i >= 0 && i < _count, "bad nmethod index"); |
kamg@551 | 107 | _nmethods[i] = nm; |
kamg@551 | 108 | } |
kamg@551 | 109 | }; |
stefank@2314 | 110 | |
stefank@2314 | 111 | #endif // SHARE_VM_RUNTIME_DTRACEJSDT_HPP |