init.cpp 5.5 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25
#include "precompiled.hpp"
26
#include "classfile/symbolTable.hpp"
27 28 29 30 31 32 33 34 35 36
#include "code/icBuffer.hpp"
#include "gc_interface/collectedHeap.hpp"
#include "interpreter/bytecodes.hpp"
#include "memory/universe.hpp"
#include "prims/methodHandles.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/icache.hpp"
#include "runtime/init.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/sharedRuntime.hpp"
D
duke 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50

// Initialization done by VM thread in vm_init_globals()
void check_ThreadShadow();
void eventlog_init();
void mutex_init();
void chunkpool_init();
void perfMemory_init();

// Initialization done by Java thread in init_globals()
void management_init();
void bytecodes_init();
void classLoader_init();
void codeCache_init();
void VM_Version_init();
51
void os_init_globals();        // depends on VM_Version_init, before universe_init
D
duke 已提交
52
void stubRoutines_init1();
53 54 55
jint universe_init();          // depends on codeCache_init and stubRoutines_init
void interpreter_init();       // before any methods loaded
void invocationCounter_init(); // before any methods loaded
D
duke 已提交
56 57 58 59
void marksweep_init();
void accessFlags_init();
void templateTable_init();
void InterfaceSupport_init();
60
void universe2_init();  // dependent on codeCache_init and stubRoutines_init, loads primordial classes
D
duke 已提交
61 62 63 64 65 66 67 68
void referenceProcessor_init();
void jni_handles_init();
void vmStructs_init();

void vtableStubs_init();
void InlineCacheBuffer_init();
void compilerOracle_init();
void compilationPolicy_init();
69
void compileBroker_init();
D
duke 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83

// Initialization after compiler initialization
bool universe_post_init();  // must happen after compiler_init
void javaClasses_init();  // must happen after vtable initialization
void stubRoutines_init2(); // note: StubRoutines need 2-phase init

// Do not disable thread-local-storage, as it is important for some
// JNI/JVM/JVMTI functions and signal handlers to work properly
// during VM shutdown
void perfMemory_exit();
void ostream_exit();

void vm_init_globals() {
  check_ThreadShadow();
84
  basic_types_init();
D
duke 已提交
85 86 87 88 89 90 91 92 93 94 95 96
  eventlog_init();
  mutex_init();
  chunkpool_init();
  perfMemory_init();
}


jint init_globals() {
  HandleMark hm;
  management_init();
  bytecodes_init();
  classLoader_init();
97
  Metaspace::global_initialize(); // must be before codeCache
D
duke 已提交
98 99
  codeCache_init();
  VM_Version_init();
100
  os_init_globals();
D
duke 已提交
101
  stubRoutines_init1();
102
  jint status = universe_init();  // dependent on codeCache_init and
103
                                  // stubRoutines_init1 and metaspace_init.
D
duke 已提交
104 105 106 107 108 109 110 111 112 113
  if (status != JNI_OK)
    return status;

  interpreter_init();  // before any methods loaded
  invocationCounter_init();  // before any methods loaded
  marksweep_init();
  accessFlags_init();
  templateTable_init();
  InterfaceSupport_init();
  SharedRuntime::generate_stubs();
114
  universe2_init();  // dependent on codeCache_init and stubRoutines_init1
D
duke 已提交
115 116
  referenceProcessor_init();
  jni_handles_init();
117
#if INCLUDE_VM_STRUCTS
D
duke 已提交
118
  vmStructs_init();
119
#endif // INCLUDE_VM_STRUCTS
D
duke 已提交
120 121 122 123 124

  vtableStubs_init();
  InlineCacheBuffer_init();
  compilerOracle_init();
  compilationPolicy_init();
125
  compileBroker_init();
D
duke 已提交
126 127 128 129 130
  VMRegImpl::set_regName();

  if (!universe_post_init()) {
    return JNI_ERR;
  }
131
  javaClasses_init();   // must happen after vtable initialization
D
duke 已提交
132 133 134 135 136 137 138 139 140 141 142
  stubRoutines_init2(); // note: StubRoutines need 2-phase init

  // Although we'd like to, we can't easily do a heap verify
  // here because the main thread isn't yet a JavaThread, so
  // its TLAB may not be made parseable from the usual interfaces.
  if (VerifyBeforeGC && !UseTLAB &&
      Universe::heap()->total_collections() >= VerifyGCStartAt) {
    Universe::heap()->prepare_for_verify();
    Universe::verify();   // make sure we're starting with a clean slate
  }

143 144 145
  // All the flags that get adjusted by VM_Version_init and os::init_2
  // have been set so dump the flags now.
  if (PrintFlagsFinal) {
F
fparain 已提交
146
    CommandLineFlags::printFlags(tty, false);
147 148
  }

D
duke 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161
  return JNI_OK;
}


void exit_globals() {
  static bool destructorsCalled = false;
  if (!destructorsCalled) {
    destructorsCalled = true;
    perfMemory_exit();
    if (PrintSafepointStatistics) {
      // Print the collected safepoint statistics.
      SafepointSynchronize::print_stat_on_exit();
    }
162 163 164 165
    if (PrintStringTableStatistics) {
      SymbolTable::dump(tty);
      StringTable::dump(tty);
    }
D
duke 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178
    ostream_exit();
  }
}


static bool _init_completed = false;

bool is_init_completed() {
  return _init_completed;
}


void set_init_completed() {
179
  assert(Universe::is_fully_initialized(), "Should have completed initialization");
D
duke 已提交
180 181
  _init_completed = true;
}