1.1 --- a/src/share/vm/compiler/compileBroker.hpp Thu Sep 02 11:40:02 2010 -0700 1.2 +++ b/src/share/vm/compiler/compileBroker.hpp Fri Sep 03 17:51:07 2010 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -41,7 +41,7 @@ 1.11 int _comp_level; 1.12 int _num_inlined_bytecodes; 1.13 nmethodLocker* _code_handle; // holder of eventual result 1.14 - CompileTask* _next; 1.15 + CompileTask* _next, *_prev; 1.16 1.17 // Fields used for logging why the compilation was initiated: 1.18 jlong _time_queued; // in units of os::elapsed_counter() 1.19 @@ -49,6 +49,7 @@ 1.20 int _hot_count; // information about its invocation counter 1.21 const char* _comment; // more info about the task 1.22 1.23 + void print_compilation(outputStream *st, methodOop method, char* method_name); 1.24 public: 1.25 CompileTask() { 1.26 _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock"); 1.27 @@ -85,15 +86,17 @@ 1.28 1.29 CompileTask* next() const { return _next; } 1.30 void set_next(CompileTask* next) { _next = next; } 1.31 + CompileTask* prev() const { return _prev; } 1.32 + void set_prev(CompileTask* prev) { _prev = prev; } 1.33 1.34 void print(); 1.35 void print_line(); 1.36 + 1.37 void print_line_on_error(outputStream* st, char* buf, int buflen); 1.38 void log_task(xmlStream* log); 1.39 void log_task_queued(); 1.40 void log_task_start(CompileLog* log); 1.41 void log_task_done(CompileLog* log); 1.42 - 1.43 }; 1.44 1.45 // CompilerCounters 1.46 @@ -141,7 +144,6 @@ 1.47 PerfCounter* compile_counter() { return _perf_compiles; } 1.48 }; 1.49 1.50 - 1.51 // CompileQueue 1.52 // 1.53 // A list of CompileTasks. 1.54 @@ -153,26 +155,42 @@ 1.55 CompileTask* _first; 1.56 CompileTask* _last; 1.57 1.58 + int _size; 1.59 public: 1.60 CompileQueue(const char* name, Monitor* lock) { 1.61 _name = name; 1.62 _lock = lock; 1.63 _first = NULL; 1.64 _last = NULL; 1.65 + _size = 0; 1.66 } 1.67 1.68 const char* name() const { return _name; } 1.69 Monitor* lock() const { return _lock; } 1.70 1.71 void add(CompileTask* task); 1.72 + void remove(CompileTask* task); 1.73 + CompileTask* first() { return _first; } 1.74 + CompileTask* last() { return _last; } 1.75 1.76 CompileTask* get(); 1.77 1.78 bool is_empty() const { return _first == NULL; } 1.79 + int size() const { return _size; } 1.80 1.81 void print(); 1.82 }; 1.83 1.84 +// CompileTaskWrapper 1.85 +// 1.86 +// Assign this task to the current thread. Deallocate the task 1.87 +// when the compilation is complete. 1.88 +class CompileTaskWrapper : StackObj { 1.89 +public: 1.90 + CompileTaskWrapper(CompileTask* task); 1.91 + ~CompileTaskWrapper(); 1.92 +}; 1.93 + 1.94 1.95 // Compilation 1.96 // 1.97 @@ -208,7 +226,8 @@ 1.98 static int _last_compile_level; 1.99 static char _last_method_compiled[name_buffer_length]; 1.100 1.101 - static CompileQueue* _method_queue; 1.102 + static CompileQueue* _c2_method_queue; 1.103 + static CompileQueue* _c1_method_queue; 1.104 static CompileTask* _task_free_list; 1.105 1.106 static GrowableArray<CompilerThread*>* _method_threads; 1.107 @@ -256,19 +275,9 @@ 1.108 static int _sum_nmethod_size; 1.109 static int _sum_nmethod_code_size; 1.110 1.111 - static int compiler_count() { 1.112 - return CICompilerCountPerCPU 1.113 - // Example: if CICompilerCountPerCPU is true, then we get 1.114 - // max(log2(8)-1,1) = 2 compiler threads on an 8-way machine. 1.115 - // May help big-app startup time. 1.116 - ? (MAX2(log2_intptr(os::active_processor_count())-1,1)) 1.117 - : CICompilerCount; 1.118 - } 1.119 - 1.120 static CompilerThread* make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS); 1.121 - static void init_compiler_threads(int compiler_count); 1.122 + static void init_compiler_threads(int c1_compiler_count, int c2_compiler_count); 1.123 static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level); 1.124 - static bool compilation_is_in_queue (methodHandle method, int osr_bci); 1.125 static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level); 1.126 static uint assign_compile_id (methodHandle method, int osr_bci); 1.127 static bool is_compile_blocking (methodHandle method, int osr_bci); 1.128 @@ -301,23 +310,35 @@ 1.129 int hot_count, 1.130 const char* comment, 1.131 TRAPS); 1.132 - 1.133 + static CompileQueue* compile_queue(int comp_level) { 1.134 + if (is_c2_compile(comp_level)) return _c2_method_queue; 1.135 + if (is_c1_compile(comp_level)) return _c1_method_queue; 1.136 + return NULL; 1.137 + } 1.138 public: 1.139 enum { 1.140 // The entry bci used for non-OSR compilations. 1.141 standard_entry_bci = InvocationEntryBci 1.142 }; 1.143 1.144 - static AbstractCompiler* compiler(int level ) { 1.145 - if (level == CompLevel_fast_compile) return _compilers[0]; 1.146 - assert(level == CompLevel_highest_tier, "what level?"); 1.147 - return _compilers[1]; 1.148 + static AbstractCompiler* compiler(int comp_level) { 1.149 + if (is_c2_compile(comp_level)) return _compilers[1]; // C2 1.150 + if (is_c1_compile(comp_level)) return _compilers[0]; // C1 1.151 + return NULL; 1.152 } 1.153 1.154 + static bool compilation_is_in_queue(methodHandle method, int osr_bci); 1.155 + static int queue_size(int comp_level) { 1.156 + CompileQueue *q = compile_queue(comp_level); 1.157 + return q != NULL ? q->size() : 0; 1.158 + } 1.159 static void compilation_init(); 1.160 static void init_compiler_thread_log(); 1.161 - static nmethod* compile_method(methodHandle method, int osr_bci, 1.162 - methodHandle hot_method, int hot_count, 1.163 + static nmethod* compile_method(methodHandle method, 1.164 + int osr_bci, 1.165 + int comp_level, 1.166 + methodHandle hot_method, 1.167 + int hot_count, 1.168 const char* comment, TRAPS); 1.169 1.170 static void compiler_thread_loop();