1 /*
   2  * Copyright (c) 1999, 2012, 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 "precompiled.hpp"
  26 #include "c1/c1_Compilation.hpp"
  27 #include "c1/c1_Compiler.hpp"
  28 #include "c1/c1_FrameMap.hpp"
  29 #include "c1/c1_GraphBuilder.hpp"
  30 #include "c1/c1_LinearScan.hpp"
  31 #include "c1/c1_MacroAssembler.hpp"
  32 #include "c1/c1_Runtime1.hpp"
  33 #include "c1/c1_ValueType.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "compiler/compilerOracle.hpp"
  36 #include "interpreter/linkResolver.hpp"
  37 #include "memory/allocation.hpp"
  38 #include "memory/allocation.inline.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "prims/nativeLookup.hpp"
  41 #include "runtime/arguments.hpp"
  42 #include "runtime/interfaceSupport.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "utilities/debug.hpp"
  45 
  46 volatile int Compiler::_runtimes = uninitialized;
  47 
  48 Compiler::Compiler() {
  49 }
  50 
  51 
  52 Compiler::~Compiler() {
  53   Unimplemented();
  54 }
  55 
  56 
  57 void Compiler::initialize_all() {
  58   BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
  59   Arena* arena = new (mtCompiler) Arena();
  60   Runtime1::initialize(buffer_blob);
  61   FrameMap::initialize();
  62   // initialize data structures
  63   ValueType::initialize(arena);
  64   // Instruction::initialize();
  65   // BlockBegin::initialize();
  66   GraphBuilder::initialize();
  67   // note: to use more than one instance of LinearScan at a time this function call has to
  68   //       be moved somewhere outside of this constructor:
  69   Interval::initialize(arena);
  70 }
  71 
  72 
  73 void Compiler::initialize() {
  74   if (_runtimes != initialized) {
  75     initialize_runtimes( initialize_all, &_runtimes);
  76   }
  77   mark_initialized();
  78 }
  79 
  80 
  81 BufferBlob* Compiler::build_buffer_blob() {
  82   // setup CodeBuffer.  Preallocate a BufferBlob of size
  83   // NMethodSizeLimit plus some extra space for constants.
  84   int code_buffer_size = Compilation::desired_max_code_buffer_size() +
  85   Compilation::desired_max_constant_size();
  86   BufferBlob* blob = BufferBlob::create("Compiler1 temporary CodeBuffer",
  87                                         code_buffer_size);
  88   if (blob == NULL) {
  89     vm_exit_out_of_memory(code_buffer_size, OOM_MALLOC_ERROR,
  90                           err_msg("Compiler1 temporary CodeBuffer.\n"
  91                                   "# Try to increase -XX:ReservedCodeCacheSize=.\n"));
  92   }
  93   return blob;
  94 }
  95 
  96 
  97 void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) {
  98   // Allocate buffer blob once at startup since allocation for each
  99   // compilation seems to be too expensive (at least on Intel win32).
 100   BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
 101   if (buffer_blob == NULL) {
 102     buffer_blob = build_buffer_blob();
 103     CompilerThread::current()->set_buffer_blob(buffer_blob);
 104   }
 105 
 106   if (!is_initialized()) {
 107     initialize();
 108   }
 109   // invoke compilation
 110   {
 111     // We are nested here because we need for the destructor
 112     // of Compilation to occur before we release the any
 113     // competing compiler thread
 114     ResourceMark rm;
 115     Compilation c(this, env, method, entry_bci, buffer_blob);
 116   }
 117 }
 118 
 119 
 120 void Compiler::print_timers() {
 121   Compilation::print_timers();
 122 }