Mon, 03 Jan 2011 14:09:11 -0500
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
Summary: enhance the error reporting mechanism to help user to fix the problem rather than making it look like a VM error.
Reviewed-by: kvn, kamg
kamg@551 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 1997, 2010, 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 |
stefank@2314 | 38 | |
kamg@551 | 39 | class RegisteredProbes; |
kamg@551 | 40 | typedef jlong OpaqueProbes; |
kamg@551 | 41 | |
kamg@551 | 42 | class DTraceJSDT : AllStatic { |
kamg@551 | 43 | private: |
kamg@551 | 44 | |
kamg@551 | 45 | static int pd_activate(void* moduleBaseAddress, jstring module, |
kamg@551 | 46 | jint providers_count, JVM_DTraceProvider* providers); |
kamg@551 | 47 | static void pd_dispose(int handle); |
kamg@551 | 48 | static jboolean pd_is_supported(); |
kamg@551 | 49 | |
kamg@551 | 50 | public: |
kamg@551 | 51 | |
kamg@551 | 52 | static OpaqueProbes activate( |
kamg@551 | 53 | jint version, jstring module_name, jint providers_count, |
kamg@551 | 54 | JVM_DTraceProvider* providers, TRAPS); |
kamg@551 | 55 | static jboolean is_probe_enabled(jmethodID method); |
kamg@551 | 56 | static void dispose(OpaqueProbes handle); |
kamg@551 | 57 | static jboolean is_supported(); |
kamg@551 | 58 | }; |
kamg@551 | 59 | |
kamg@551 | 60 | class RegisteredProbes : public CHeapObj { |
kamg@551 | 61 | private: |
kamg@551 | 62 | nmethod** _nmethods; // all the probe methods |
kamg@551 | 63 | size_t _count; // number of probe methods |
kamg@551 | 64 | int _helper_handle; // DTrace-assigned identifier |
kamg@551 | 65 | |
kamg@551 | 66 | public: |
kamg@551 | 67 | RegisteredProbes(size_t count) { |
kamg@551 | 68 | _count = count; |
kamg@551 | 69 | _nmethods = NEW_C_HEAP_ARRAY(nmethod*, count); |
kamg@551 | 70 | } |
kamg@551 | 71 | |
kamg@551 | 72 | ~RegisteredProbes() { |
kamg@551 | 73 | for (size_t i = 0; i < _count; ++i) { |
kamg@551 | 74 | // Let the sweeper reclaim it |
kamg@551 | 75 | _nmethods[i]->make_not_entrant(); |
kamg@551 | 76 | _nmethods[i]->method()->clear_code(); |
kamg@551 | 77 | } |
kamg@551 | 78 | FREE_C_HEAP_ARRAY(nmethod*, _nmethods); |
kamg@551 | 79 | _nmethods = NULL; |
kamg@551 | 80 | _count = 0; |
kamg@551 | 81 | } |
kamg@551 | 82 | |
kamg@551 | 83 | static RegisteredProbes* toRegisteredProbes(OpaqueProbes p) { |
kamg@551 | 84 | return (RegisteredProbes*)(intptr_t)p; |
kamg@551 | 85 | } |
kamg@551 | 86 | |
kamg@551 | 87 | static OpaqueProbes toOpaqueProbes(RegisteredProbes* p) { |
kamg@551 | 88 | return (OpaqueProbes)(intptr_t)p; |
kamg@551 | 89 | } |
kamg@551 | 90 | |
kamg@551 | 91 | void set_helper_handle(int handle) { _helper_handle = handle; } |
kamg@551 | 92 | int helper_handle() const { return _helper_handle; } |
kamg@551 | 93 | |
kamg@551 | 94 | nmethod* nmethod_at(size_t i) { |
kamg@551 | 95 | assert(i >= 0 && i < _count, "bad nmethod index"); |
kamg@551 | 96 | return _nmethods[i]; |
kamg@551 | 97 | } |
kamg@551 | 98 | |
kamg@551 | 99 | void nmethod_at_put(size_t i, nmethod* nm) { |
kamg@551 | 100 | assert(i >= 0 && i < _count, "bad nmethod index"); |
kamg@551 | 101 | _nmethods[i] = nm; |
kamg@551 | 102 | } |
kamg@551 | 103 | }; |
stefank@2314 | 104 | |
stefank@2314 | 105 | #endif // SHARE_VM_RUNTIME_DTRACEJSDT_HPP |