1 /* 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "incls/_precompiled.incl" 26 #include "incls/_c1_Compiler.cpp.incl" 27 28 volatile int Compiler::_runtimes = uninitialized; 29 30 Compiler::Compiler() { 31 } 32 33 34 Compiler::~Compiler() { 35 Unimplemented(); 36 } 37 38 39 void Compiler::initialize_all() { 40 BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob(); 41 Arena* arena = new Arena(); 42 Runtime1::initialize(buffer_blob); 43 FrameMap::initialize(); 44 // initialize data structures 45 ValueType::initialize(arena); 46 // Instruction::initialize(); 47 // BlockBegin::initialize(); 48 GraphBuilder::initialize(); 49 // note: to use more than on instance of LinearScan at a time this function call has to 50 // be moved somewhere outside of this constructor: 51 Interval::initialize(arena); 52 } 53 54 55 void Compiler::initialize() { 56 if (_runtimes != initialized) { 57 ciEnv* env = ciEnv::current(); 58 initialize_runtimes( initialize_all, &_runtimes); 59 } 60 mark_initialized(); 61 } 62 63 64 BufferBlob* Compiler::build_buffer_blob() { 65 // setup CodeBuffer. Preallocate a BufferBlob of size 66 // NMethodSizeLimit plus some extra space for constants. 67 int code_buffer_size = Compilation::desired_max_code_buffer_size() + 68 Compilation::desired_max_constant_size(); 69 BufferBlob* blob = BufferBlob::create("Compiler1 temporary CodeBuffer", 70 code_buffer_size); 71 guarantee(blob != NULL, "must create initial code buffer"); 72 return blob; 73 } 74 75 76 void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) { 77 // Allocate buffer blob once at startup since allocation for each 78 // compilation seems to be too expensive (at least on Intel win32). 79 BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob(); 80 if (buffer_blob == NULL) { 81 buffer_blob = build_buffer_blob(); 82 CompilerThread::current()->set_buffer_blob(buffer_blob); 83 } 84 85 if (!is_initialized()) { 86 initialize(); 87 } 88 // invoke compilation 89 { 90 // We are nested here because we need for the destructor 91 // of Compilation to occur before we release the any 92 // competing compiler thread 93 ResourceMark rm; 94 Compilation c(this, env, method, entry_bci, buffer_blob); 95 } 96 } 97 98 99 void Compiler::print_timers() { 100 Compilation::print_timers(); 101 }