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
duke@435 | 1 | /* |
never@3499 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 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. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
coleenp@3865 | 26 | #include "classfile/symbolTable.hpp" |
stefank@2314 | 27 | #include "code/icBuffer.hpp" |
stefank@2314 | 28 | #include "gc_interface/collectedHeap.hpp" |
stefank@2314 | 29 | #include "interpreter/bytecodes.hpp" |
stefank@2314 | 30 | #include "memory/universe.hpp" |
stefank@2314 | 31 | #include "prims/methodHandles.hpp" |
stefank@2314 | 32 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 33 | #include "runtime/icache.hpp" |
stefank@2314 | 34 | #include "runtime/init.hpp" |
stefank@2314 | 35 | #include "runtime/safepoint.hpp" |
stefank@2314 | 36 | #include "runtime/sharedRuntime.hpp" |
jprovino@4542 | 37 | #include "utilities/macros.hpp" |
duke@435 | 38 | |
duke@435 | 39 | // Initialization done by VM thread in vm_init_globals() |
duke@435 | 40 | void check_ThreadShadow(); |
duke@435 | 41 | void eventlog_init(); |
duke@435 | 42 | void mutex_init(); |
duke@435 | 43 | void chunkpool_init(); |
duke@435 | 44 | void perfMemory_init(); |
duke@435 | 45 | |
duke@435 | 46 | // Initialization done by Java thread in init_globals() |
duke@435 | 47 | void management_init(); |
duke@435 | 48 | void bytecodes_init(); |
duke@435 | 49 | void classLoader_init(); |
duke@435 | 50 | void codeCache_init(); |
duke@435 | 51 | void VM_Version_init(); |
phh@3378 | 52 | void os_init_globals(); // depends on VM_Version_init, before universe_init |
duke@435 | 53 | void stubRoutines_init1(); |
phh@3378 | 54 | jint universe_init(); // depends on codeCache_init and stubRoutines_init |
phh@3378 | 55 | void interpreter_init(); // before any methods loaded |
phh@3378 | 56 | void invocationCounter_init(); // before any methods loaded |
duke@435 | 57 | void marksweep_init(); |
duke@435 | 58 | void accessFlags_init(); |
duke@435 | 59 | void templateTable_init(); |
duke@435 | 60 | void InterfaceSupport_init(); |
phh@3378 | 61 | void universe2_init(); // dependent on codeCache_init and stubRoutines_init, loads primordial classes |
duke@435 | 62 | void referenceProcessor_init(); |
duke@435 | 63 | void jni_handles_init(); |
duke@435 | 64 | void vmStructs_init(); |
duke@435 | 65 | |
duke@435 | 66 | void vtableStubs_init(); |
duke@435 | 67 | void InlineCacheBuffer_init(); |
duke@435 | 68 | void compilerOracle_init(); |
duke@435 | 69 | void compilationPolicy_init(); |
never@3499 | 70 | void compileBroker_init(); |
duke@435 | 71 | |
duke@435 | 72 | // Initialization after compiler initialization |
duke@435 | 73 | bool universe_post_init(); // must happen after compiler_init |
duke@435 | 74 | void javaClasses_init(); // must happen after vtable initialization |
duke@435 | 75 | void stubRoutines_init2(); // note: StubRoutines need 2-phase init |
duke@435 | 76 | |
duke@435 | 77 | // Do not disable thread-local-storage, as it is important for some |
duke@435 | 78 | // JNI/JVM/JVMTI functions and signal handlers to work properly |
duke@435 | 79 | // during VM shutdown |
duke@435 | 80 | void perfMemory_exit(); |
duke@435 | 81 | void ostream_exit(); |
duke@435 | 82 | |
duke@435 | 83 | void vm_init_globals() { |
duke@435 | 84 | check_ThreadShadow(); |
coleenp@548 | 85 | basic_types_init(); |
duke@435 | 86 | eventlog_init(); |
duke@435 | 87 | mutex_init(); |
duke@435 | 88 | chunkpool_init(); |
duke@435 | 89 | perfMemory_init(); |
duke@435 | 90 | } |
duke@435 | 91 | |
duke@435 | 92 | |
duke@435 | 93 | jint init_globals() { |
duke@435 | 94 | HandleMark hm; |
duke@435 | 95 | management_init(); |
duke@435 | 96 | bytecodes_init(); |
duke@435 | 97 | classLoader_init(); |
coleenp@4037 | 98 | Metaspace::global_initialize(); // must be before codeCache |
duke@435 | 99 | codeCache_init(); |
duke@435 | 100 | VM_Version_init(); |
phh@3378 | 101 | os_init_globals(); |
duke@435 | 102 | stubRoutines_init1(); |
phh@3378 | 103 | jint status = universe_init(); // dependent on codeCache_init and |
coleenp@4037 | 104 | // stubRoutines_init1 and metaspace_init. |
duke@435 | 105 | if (status != JNI_OK) |
duke@435 | 106 | return status; |
duke@435 | 107 | |
duke@435 | 108 | interpreter_init(); // before any methods loaded |
duke@435 | 109 | invocationCounter_init(); // before any methods loaded |
duke@435 | 110 | marksweep_init(); |
duke@435 | 111 | accessFlags_init(); |
duke@435 | 112 | templateTable_init(); |
duke@435 | 113 | InterfaceSupport_init(); |
duke@435 | 114 | SharedRuntime::generate_stubs(); |
phh@3378 | 115 | universe2_init(); // dependent on codeCache_init and stubRoutines_init1 |
duke@435 | 116 | referenceProcessor_init(); |
duke@435 | 117 | jni_handles_init(); |
jprovino@4165 | 118 | #if INCLUDE_VM_STRUCTS |
duke@435 | 119 | vmStructs_init(); |
jprovino@4165 | 120 | #endif // INCLUDE_VM_STRUCTS |
duke@435 | 121 | |
duke@435 | 122 | vtableStubs_init(); |
duke@435 | 123 | InlineCacheBuffer_init(); |
duke@435 | 124 | compilerOracle_init(); |
duke@435 | 125 | compilationPolicy_init(); |
never@3499 | 126 | compileBroker_init(); |
duke@435 | 127 | VMRegImpl::set_regName(); |
duke@435 | 128 | |
duke@435 | 129 | if (!universe_post_init()) { |
duke@435 | 130 | return JNI_ERR; |
duke@435 | 131 | } |
phh@3378 | 132 | javaClasses_init(); // must happen after vtable initialization |
duke@435 | 133 | stubRoutines_init2(); // note: StubRoutines need 2-phase init |
duke@435 | 134 | |
duke@435 | 135 | // Although we'd like to, we can't easily do a heap verify |
duke@435 | 136 | // here because the main thread isn't yet a JavaThread, so |
duke@435 | 137 | // its TLAB may not be made parseable from the usual interfaces. |
duke@435 | 138 | if (VerifyBeforeGC && !UseTLAB && |
duke@435 | 139 | Universe::heap()->total_collections() >= VerifyGCStartAt) { |
duke@435 | 140 | Universe::heap()->prepare_for_verify(); |
duke@435 | 141 | Universe::verify(); // make sure we're starting with a clean slate |
duke@435 | 142 | } |
duke@435 | 143 | |
never@2085 | 144 | // All the flags that get adjusted by VM_Version_init and os::init_2 |
never@2085 | 145 | // have been set so dump the flags now. |
never@2085 | 146 | if (PrintFlagsFinal) { |
fparain@3402 | 147 | CommandLineFlags::printFlags(tty, false); |
never@2085 | 148 | } |
never@2085 | 149 | |
duke@435 | 150 | return JNI_OK; |
duke@435 | 151 | } |
duke@435 | 152 | |
duke@435 | 153 | |
duke@435 | 154 | void exit_globals() { |
duke@435 | 155 | static bool destructorsCalled = false; |
duke@435 | 156 | if (!destructorsCalled) { |
duke@435 | 157 | destructorsCalled = true; |
duke@435 | 158 | perfMemory_exit(); |
duke@435 | 159 | if (PrintSafepointStatistics) { |
duke@435 | 160 | // Print the collected safepoint statistics. |
duke@435 | 161 | SafepointSynchronize::print_stat_on_exit(); |
duke@435 | 162 | } |
coleenp@3865 | 163 | if (PrintStringTableStatistics) { |
coleenp@3865 | 164 | SymbolTable::dump(tty); |
coleenp@3865 | 165 | StringTable::dump(tty); |
coleenp@3865 | 166 | } |
duke@435 | 167 | ostream_exit(); |
duke@435 | 168 | } |
duke@435 | 169 | } |
duke@435 | 170 | |
duke@435 | 171 | |
duke@435 | 172 | static bool _init_completed = false; |
duke@435 | 173 | |
duke@435 | 174 | bool is_init_completed() { |
duke@435 | 175 | return _init_completed; |
duke@435 | 176 | } |
duke@435 | 177 | |
duke@435 | 178 | |
duke@435 | 179 | void set_init_completed() { |
ysr@2301 | 180 | assert(Universe::is_fully_initialized(), "Should have completed initialization"); |
duke@435 | 181 | _init_completed = true; |
duke@435 | 182 | } |