duke@435: /* mikael@6198: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "c1/c1_Compilation.hpp" stefank@2314: #include "c1/c1_Compiler.hpp" stefank@2314: #include "c1/c1_FrameMap.hpp" stefank@2314: #include "c1/c1_GraphBuilder.hpp" stefank@2314: #include "c1/c1_LinearScan.hpp" stefank@2314: #include "c1/c1_MacroAssembler.hpp" stefank@2314: #include "c1/c1_Runtime1.hpp" stefank@2314: #include "c1/c1_ValueType.hpp" stefank@2314: #include "compiler/compileBroker.hpp" stefank@2314: #include "compiler/compilerOracle.hpp" stefank@2314: #include "interpreter/linkResolver.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "prims/nativeLookup.hpp" stefank@2314: #include "runtime/arguments.hpp" stefank@2314: #include "runtime/interfaceSupport.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" duke@435: duke@435: anoll@5919: Compiler::Compiler () {} duke@435: anoll@5919: void Compiler::init_c1_runtime() { iveresov@1939: BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob(); zgu@7074: Arena* arena = new (mtCompiler) Arena(mtCompiler); iveresov@1939: Runtime1::initialize(buffer_blob); iveresov@1939: FrameMap::initialize(); iveresov@1939: // initialize data structures iveresov@1939: ValueType::initialize(arena); iveresov@1939: GraphBuilder::initialize(); iveresov@1939: // note: to use more than one instance of LinearScan at a time this function call has to iveresov@1939: // be moved somewhere outside of this constructor: iveresov@1939: Interval::initialize(arena); iveresov@1939: } iveresov@1939: iveresov@1939: duke@435: void Compiler::initialize() { anoll@5919: // Buffer blob must be allocated per C1 compiler thread at startup anoll@5919: BufferBlob* buffer_blob = init_buffer_blob(); anoll@5919: anoll@5919: if (should_perform_init()) { anoll@5919: if (buffer_blob == NULL) { anoll@5919: // When we come here we are in state 'initializing'; entire C1 compilation anoll@5919: // can be shut down. anoll@5919: set_state(failed); anoll@5919: } else { anoll@5919: init_c1_runtime(); anoll@5919: set_state(initialized); anoll@5919: } duke@435: } duke@435: } duke@435: anoll@5919: BufferBlob* Compiler::init_buffer_blob() { anoll@5157: // Allocate buffer blob once at startup since allocation for each anoll@5157: // compilation seems to be too expensive (at least on Intel win32). anoll@5919: assert (CompilerThread::current()->get_buffer_blob() == NULL, "Should initialize only once"); anoll@5157: iveresov@1939: // setup CodeBuffer. Preallocate a BufferBlob of size iveresov@1939: // NMethodSizeLimit plus some extra space for constants. iveresov@1939: int code_buffer_size = Compilation::desired_max_code_buffer_size() + iveresov@1939: Compilation::desired_max_constant_size(); anoll@5157: anoll@5919: BufferBlob* buffer_blob = BufferBlob::create("C1 temporary CodeBuffer", code_buffer_size); anoll@5919: if (buffer_blob != NULL) { anoll@5157: CompilerThread::current()->set_buffer_blob(buffer_blob); anoll@5157: } anoll@5157: anoll@5157: return buffer_blob; iveresov@1939: } iveresov@1939: iveresov@1939: duke@435: void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) { anoll@5919: BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob(); anoll@5919: assert(buffer_blob != NULL, "Must exist"); duke@435: // invoke compilation duke@435: { duke@435: // We are nested here because we need for the destructor duke@435: // of Compilation to occur before we release the any duke@435: // competing compiler thread duke@435: ResourceMark rm; iveresov@1939: Compilation c(this, env, method, entry_bci, buffer_blob); duke@435: } duke@435: } duke@435: duke@435: duke@435: void Compiler::print_timers() { duke@435: Compilation::print_timers(); duke@435: }