c1_Compiler.cpp 3.9 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1999, 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include "precompiled.hpp"
#include "c1/c1_Compilation.hpp"
#include "c1/c1_Compiler.hpp"
#include "c1/c1_FrameMap.hpp"
#include "c1/c1_GraphBuilder.hpp"
#include "c1/c1_LinearScan.hpp"
#include "c1/c1_MacroAssembler.hpp"
#include "c1/c1_Runtime1.hpp"
#include "c1/c1_ValueType.hpp"
#include "compiler/compileBroker.hpp"
#include "compiler/compilerOracle.hpp"
#include "interpreter/linkResolver.hpp"
#include "memory/allocation.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.hpp"
#include "prims/nativeLookup.hpp"
#include "runtime/arguments.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/sharedRuntime.hpp"
D
duke 已提交
44 45 46 47 48 49 50 51 52 53 54 55

volatile int Compiler::_runtimes = uninitialized;

Compiler::Compiler() {
}


Compiler::~Compiler() {
  Unimplemented();
}


56 57
void Compiler::initialize_all() {
  BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
Z
zgu 已提交
58
  Arena* arena = new (mtCompiler) Arena();
59 60 61 62 63 64 65 66 67 68 69 70 71
  Runtime1::initialize(buffer_blob);
  FrameMap::initialize();
  // initialize data structures
  ValueType::initialize(arena);
  // Instruction::initialize();
  // BlockBegin::initialize();
  GraphBuilder::initialize();
  // note: to use more than one instance of LinearScan at a time this function call has to
  //       be moved somewhere outside of this constructor:
  Interval::initialize(arena);
}


D
duke 已提交
72 73
void Compiler::initialize() {
  if (_runtimes != initialized) {
74
    initialize_runtimes( initialize_all, &_runtimes);
D
duke 已提交
75 76 77 78 79
  }
  mark_initialized();
}


80 81 82 83 84 85 86 87
BufferBlob* Compiler::get_buffer_blob(ciEnv* env) {
  // Allocate buffer blob once at startup since allocation for each
  // compilation seems to be too expensive (at least on Intel win32).
  BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
  if (buffer_blob != NULL) {
    return buffer_blob;
  }

88 89 90 91
  // setup CodeBuffer.  Preallocate a BufferBlob of size
  // NMethodSizeLimit plus some extra space for constants.
  int code_buffer_size = Compilation::desired_max_code_buffer_size() +
    Compilation::desired_max_constant_size();
92 93 94 95 96 97 98 99 100 101 102

  buffer_blob = BufferBlob::create("Compiler1 temporary CodeBuffer",
                                   code_buffer_size);
  if (buffer_blob == NULL) {
    CompileBroker::handle_full_code_cache();
    env->record_failure("CodeCache is full");
  } else {
    CompilerThread::current()->set_buffer_blob(buffer_blob);
  }

  return buffer_blob;
103 104 105
}


D
duke 已提交
106
void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) {
107
  BufferBlob* buffer_blob = Compiler::get_buffer_blob(env);
108
  if (buffer_blob == NULL) {
109
    return;
110
  }
D
duke 已提交
111 112 113 114

  if (!is_initialized()) {
    initialize();
  }
115

D
duke 已提交
116 117 118 119 120 121
  // invoke compilation
  {
    // We are nested here because we need for the destructor
    // of Compilation to occur before we release the any
    // competing compiler thread
    ResourceMark rm;
122
    Compilation c(this, env, method, entry_bci, buffer_blob);
D
duke 已提交
123 124 125 126 127 128 129
  }
}


void Compiler::print_timers() {
  Compilation::print_timers();
}