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
jrose@535 | 1 | /* |
minqi@4093 | 2 | * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. |
jrose@535 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jrose@535 | 4 | * |
jrose@535 | 5 | * This code is free software; you can redistribute it and/or modify it |
jrose@535 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jrose@535 | 7 | * published by the Free Software Foundation. |
jrose@535 | 8 | * |
jrose@535 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jrose@535 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jrose@535 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jrose@535 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jrose@535 | 13 | * accompanied this code). |
jrose@535 | 14 | * |
jrose@535 | 15 | * You should have received a copy of the GNU General Public License version |
jrose@535 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jrose@535 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jrose@535 | 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. |
jrose@535 | 22 | * |
jrose@535 | 23 | */ |
jrose@535 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_COMPILER_DISASSEMBLER_HPP |
stefank@2314 | 26 | #define SHARE_VM_COMPILER_DISASSEMBLER_HPP |
stefank@2314 | 27 | |
kvn@4107 | 28 | #include "asm/codeBuffer.hpp" |
stefank@2314 | 29 | #include "runtime/globals.hpp" |
stefank@2314 | 30 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 31 | # include "os_linux.inline.hpp" |
stefank@2314 | 32 | #endif |
stefank@2314 | 33 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 34 | # include "os_solaris.inline.hpp" |
stefank@2314 | 35 | #endif |
stefank@2314 | 36 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 37 | # include "os_windows.inline.hpp" |
stefank@2314 | 38 | #endif |
never@3156 | 39 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 40 | # include "os_bsd.inline.hpp" |
never@3156 | 41 | #endif |
stefank@2314 | 42 | |
jrose@535 | 43 | class decode_env; |
jrose@535 | 44 | |
jrose@535 | 45 | // The disassembler prints out assembly code annotated |
jrose@535 | 46 | // with Java specific information. |
jrose@535 | 47 | |
jrose@535 | 48 | class Disassembler { |
jrose@535 | 49 | friend class decode_env; |
jrose@535 | 50 | private: |
jrose@535 | 51 | // this is the type of the dll entry point: |
minqi@4244 | 52 | typedef void* (*decode_func_virtual)(uintptr_t start_va, uintptr_t end_va, |
minqi@4093 | 53 | unsigned char* buffer, uintptr_t length, |
jrose@535 | 54 | void* (*event_callback)(void*, const char*, void*), |
jrose@535 | 55 | void* event_stream, |
jrose@535 | 56 | int (*printf_callback)(void*, const char*, ...), |
jrose@535 | 57 | void* printf_stream, |
minqi@4244 | 58 | const char* options, |
minqi@4244 | 59 | int newline); |
minqi@4244 | 60 | // this is the type of the dll entry point for old version: |
minqi@4244 | 61 | typedef void* (*decode_func)(void* start_va, void* end_va, |
minqi@4244 | 62 | void* (*event_callback)(void*, const char*, void*), |
minqi@4244 | 63 | void* event_stream, |
minqi@4244 | 64 | int (*printf_callback)(void*, const char*, ...), |
minqi@4244 | 65 | void* printf_stream, |
jrose@535 | 66 | const char* options); |
jrose@535 | 67 | // points to the library. |
jrose@535 | 68 | static void* _library; |
jrose@535 | 69 | // bailout |
jrose@535 | 70 | static bool _tried_to_load_library; |
jrose@535 | 71 | // points to the decode function. |
minqi@4244 | 72 | static decode_func_virtual _decode_instructions_virtual; |
jrose@535 | 73 | static decode_func _decode_instructions; |
jrose@535 | 74 | // tries to load library and return whether it succedded. |
jrose@535 | 75 | static bool load_library(); |
jrose@535 | 76 | |
jrose@535 | 77 | // Machine dependent stuff |
stefank@2314 | 78 | #ifdef TARGET_ARCH_x86 |
stefank@2314 | 79 | # include "disassembler_x86.hpp" |
stefank@2314 | 80 | #endif |
stefank@2314 | 81 | #ifdef TARGET_ARCH_sparc |
stefank@2314 | 82 | # include "disassembler_sparc.hpp" |
stefank@2314 | 83 | #endif |
stefank@2314 | 84 | #ifdef TARGET_ARCH_zero |
stefank@2314 | 85 | # include "disassembler_zero.hpp" |
stefank@2314 | 86 | #endif |
bobv@2508 | 87 | #ifdef TARGET_ARCH_arm |
bobv@2508 | 88 | # include "disassembler_arm.hpp" |
bobv@2508 | 89 | #endif |
bobv@2508 | 90 | #ifdef TARGET_ARCH_ppc |
bobv@2508 | 91 | # include "disassembler_ppc.hpp" |
bobv@2508 | 92 | #endif |
stefank@2314 | 93 | |
jrose@535 | 94 | |
jrose@535 | 95 | public: |
jrose@535 | 96 | static bool can_decode() { |
minqi@4244 | 97 | return (_decode_instructions_virtual != NULL) || |
minqi@4244 | 98 | (_decode_instructions != NULL) || |
minqi@4244 | 99 | load_library(); |
jrose@535 | 100 | } |
jrose@535 | 101 | static void decode(CodeBlob *cb, outputStream* st = NULL); |
jrose@535 | 102 | static void decode(nmethod* nm, outputStream* st = NULL); |
roland@4767 | 103 | static void decode(address begin, address end, outputStream* st = NULL, CodeStrings c = CodeStrings()); |
jrose@535 | 104 | }; |
stefank@2314 | 105 | |
stefank@2314 | 106 | #endif // SHARE_VM_COMPILER_DISASSEMBLER_HPP |