comparison src/share/vm/c1/c1_Compiler.cpp @ 12880:469216acdb28

8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash Summary: Ensure ensure correct initialization of compiler runtime Reviewed-by: kvn, twisti
author anoll
date Thu, 10 Oct 2013 15:44:12 +0200
parents 01e51113b4f5
children 096c224171c4 de6a9e811145
comparison
equal deleted inserted replaced
12876:8b80b262e501 12880:469216acdb28
40 #include "prims/nativeLookup.hpp" 40 #include "prims/nativeLookup.hpp"
41 #include "runtime/arguments.hpp" 41 #include "runtime/arguments.hpp"
42 #include "runtime/interfaceSupport.hpp" 42 #include "runtime/interfaceSupport.hpp"
43 #include "runtime/sharedRuntime.hpp" 43 #include "runtime/sharedRuntime.hpp"
44 44
45 volatile int Compiler::_runtimes = uninitialized;
46 45
47 Compiler::Compiler() { 46 Compiler::Compiler () {}
48 }
49 47
50 48 void Compiler::init_c1_runtime() {
51 Compiler::~Compiler() {
52 Unimplemented();
53 }
54
55
56 void Compiler::initialize_all() {
57 BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob(); 49 BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
58 Arena* arena = new (mtCompiler) Arena(); 50 Arena* arena = new (mtCompiler) Arena();
59 Runtime1::initialize(buffer_blob); 51 Runtime1::initialize(buffer_blob);
60 FrameMap::initialize(); 52 FrameMap::initialize();
61 // initialize data structures 53 // initialize data structures
62 ValueType::initialize(arena); 54 ValueType::initialize(arena);
63 // Instruction::initialize();
64 // BlockBegin::initialize();
65 GraphBuilder::initialize(); 55 GraphBuilder::initialize();
66 // note: to use more than one instance of LinearScan at a time this function call has to 56 // note: to use more than one instance of LinearScan at a time this function call has to
67 // be moved somewhere outside of this constructor: 57 // be moved somewhere outside of this constructor:
68 Interval::initialize(arena); 58 Interval::initialize(arena);
69 } 59 }
70 60
71 61
72 void Compiler::initialize() { 62 void Compiler::initialize() {
73 if (_runtimes != initialized) { 63 // Buffer blob must be allocated per C1 compiler thread at startup
74 initialize_runtimes( initialize_all, &_runtimes); 64 BufferBlob* buffer_blob = init_buffer_blob();
65
66 if (should_perform_init()) {
67 if (buffer_blob == NULL) {
68 // When we come here we are in state 'initializing'; entire C1 compilation
69 // can be shut down.
70 set_state(failed);
71 } else {
72 init_c1_runtime();
73 set_state(initialized);
74 }
75 } 75 }
76 mark_initialized();
77 } 76 }
78 77
79 78 BufferBlob* Compiler::init_buffer_blob() {
80 BufferBlob* Compiler::get_buffer_blob(ciEnv* env) {
81 // Allocate buffer blob once at startup since allocation for each 79 // Allocate buffer blob once at startup since allocation for each
82 // compilation seems to be too expensive (at least on Intel win32). 80 // compilation seems to be too expensive (at least on Intel win32).
83 BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob(); 81 assert (CompilerThread::current()->get_buffer_blob() == NULL, "Should initialize only once");
84 if (buffer_blob != NULL) {
85 return buffer_blob;
86 }
87 82
88 // setup CodeBuffer. Preallocate a BufferBlob of size 83 // setup CodeBuffer. Preallocate a BufferBlob of size
89 // NMethodSizeLimit plus some extra space for constants. 84 // NMethodSizeLimit plus some extra space for constants.
90 int code_buffer_size = Compilation::desired_max_code_buffer_size() + 85 int code_buffer_size = Compilation::desired_max_code_buffer_size() +
91 Compilation::desired_max_constant_size(); 86 Compilation::desired_max_constant_size();
92 87
93 buffer_blob = BufferBlob::create("Compiler1 temporary CodeBuffer", 88 BufferBlob* buffer_blob = BufferBlob::create("C1 temporary CodeBuffer", code_buffer_size);
94 code_buffer_size); 89 if (buffer_blob != NULL) {
95 if (buffer_blob == NULL) {
96 CompileBroker::handle_full_code_cache();
97 env->record_failure("CodeCache is full");
98 } else {
99 CompilerThread::current()->set_buffer_blob(buffer_blob); 90 CompilerThread::current()->set_buffer_blob(buffer_blob);
100 } 91 }
101 92
102 return buffer_blob; 93 return buffer_blob;
103 } 94 }
104 95
105 96
106 void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) { 97 void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) {
107 BufferBlob* buffer_blob = Compiler::get_buffer_blob(env); 98 BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
108 if (buffer_blob == NULL) { 99 assert(buffer_blob != NULL, "Must exist");
109 return;
110 }
111
112 if (!is_initialized()) {
113 initialize();
114 }
115
116 // invoke compilation 100 // invoke compilation
117 { 101 {
118 // We are nested here because we need for the destructor 102 // We are nested here because we need for the destructor
119 // of Compilation to occur before we release the any 103 // of Compilation to occur before we release the any
120 // competing compiler thread 104 // competing compiler thread