src/share/vm/utilities/decoder.cpp

Thu, 27 Jan 2011 16:11:27 -0800

author
coleenp
date
Thu, 27 Jan 2011 16:11:27 -0800
changeset 2497
3582bf76420e
parent 2364
2d4762ec74af
child 3156
f08d439fab8c
permissions
-rw-r--r--

6990754: Use native memory and reference counting to implement SymbolTable
Summary: move symbols from permgen into C heap and reference count them
Reviewed-by: never, acorn, jmasa, stefank

zgu@2364 1 /*
zgu@2364 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
zgu@2364 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@2364 4 *
zgu@2364 5 * This code is free software; you can redistribute it and/or modify it
zgu@2364 6 * under the terms of the GNU General Public License version 2 only, as
zgu@2364 7 * published by the Free Software Foundation.
zgu@2364 8 *
zgu@2364 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@2364 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@2364 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@2364 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@2364 13 * accompanied this code).
zgu@2364 14 *
zgu@2364 15 * You should have received a copy of the GNU General Public License version
zgu@2364 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@2364 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@2364 18 *
zgu@2364 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@2364 20 * or visit www.oracle.com if you need additional information or have any
zgu@2364 21 * questions.
zgu@2364 22 *
zgu@2364 23 */
zgu@2364 24
zgu@2364 25 #include "precompiled.hpp"
zgu@2364 26 #include "prims/jvm.h"
zgu@2364 27 #include "utilities/decoder.hpp"
zgu@2364 28
zgu@2364 29 Decoder::decoder_status Decoder::_decoder_status = Decoder::no_error;
zgu@2364 30 bool Decoder::_initialized = false;
zgu@2364 31
zgu@2364 32 #ifndef _WINDOWS
zgu@2364 33
zgu@2364 34 // Implementation of common functionalities among Solaris and Linux
zgu@2364 35 #include "utilities/elfFile.hpp"
zgu@2364 36
zgu@2364 37 ElfFile* Decoder::_opened_elf_files = NULL;
zgu@2364 38
zgu@2364 39 bool Decoder::can_decode_C_frame_in_vm() {
zgu@2364 40 return true;
zgu@2364 41 }
zgu@2364 42
zgu@2364 43 void Decoder::initialize() {
zgu@2364 44 _initialized = true;
zgu@2364 45 }
zgu@2364 46
zgu@2364 47 void Decoder::uninitialize() {
zgu@2364 48 if (_opened_elf_files != NULL) {
zgu@2364 49 delete _opened_elf_files;
zgu@2364 50 _opened_elf_files = NULL;
zgu@2364 51 }
zgu@2364 52 _initialized = false;
zgu@2364 53 }
zgu@2364 54
zgu@2364 55 Decoder::decoder_status Decoder::decode(address addr, const char* filepath, char *buf, int buflen, int *offset) {
zgu@2364 56 if (_decoder_status != no_error) {
zgu@2364 57 return _decoder_status;
zgu@2364 58 }
zgu@2364 59
zgu@2364 60 ElfFile* file = get_elf_file(filepath);
zgu@2364 61 if (_decoder_status != no_error) {
zgu@2364 62 return _decoder_status;
zgu@2364 63 }
zgu@2364 64
zgu@2364 65 const char* symbol = file->decode(addr, offset);
zgu@2364 66 if (file->get_status() == out_of_memory) {
zgu@2364 67 _decoder_status = out_of_memory;
zgu@2364 68 return _decoder_status;
zgu@2364 69 } else if (symbol != NULL) {
zgu@2364 70 if (!demangle(symbol, buf, buflen)) {
zgu@2364 71 jio_snprintf(buf, buflen, "%s", symbol);
zgu@2364 72 }
zgu@2364 73 return no_error;
zgu@2364 74 } else {
zgu@2364 75 return symbol_not_found;
zgu@2364 76 }
zgu@2364 77 }
zgu@2364 78
zgu@2364 79 ElfFile* Decoder::get_elf_file(const char* filepath) {
zgu@2364 80 if (_decoder_status != no_error) {
zgu@2364 81 return NULL;
zgu@2364 82 }
zgu@2364 83 ElfFile* file = _opened_elf_files;
zgu@2364 84 while (file != NULL) {
zgu@2364 85 if (file->same_elf_file(filepath)) {
zgu@2364 86 return file;
zgu@2364 87 }
zgu@2364 88 file = file->m_next;
zgu@2364 89 }
zgu@2364 90
zgu@2364 91 file = new ElfFile(filepath);
zgu@2364 92 if (file == NULL) {
zgu@2364 93 _decoder_status = out_of_memory;
zgu@2364 94 }
zgu@2364 95 if (_opened_elf_files != NULL) {
zgu@2364 96 file->m_next = _opened_elf_files;
zgu@2364 97 }
zgu@2364 98
zgu@2364 99 _opened_elf_files = file;
zgu@2364 100 return file;
zgu@2364 101 }
zgu@2364 102
zgu@2364 103 #endif
zgu@2364 104

mercurial