src/share/vm/runtime/compilationPolicy.cpp

changeset 26
ed5b982c0b0e
parent 1
2d8a650513c2
child 6876
710a3c8b516e
equal deleted inserted replaced
25:873fd82b133d 26:ed5b982c0b0e
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
30
31 #include "precompiled.hpp" 25 #include "precompiled.hpp"
32 #include "code/compiledIC.hpp" 26 #include "code/compiledIC.hpp"
33 #include "code/nmethod.hpp" 27 #include "code/nmethod.hpp"
34 #include "code/scopeDesc.hpp" 28 #include "code/scopeDesc.hpp"
35 #include "compiler/compilerOracle.hpp" 29 #include "compiler/compilerOracle.hpp"
343 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); 337 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
344 mcs->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); 338 mcs->backedge_counter()->set_state(InvocationCounter::wait_for_nothing);
345 } 339 }
346 } 340 }
347 341
348 #ifdef MIPS64
349 bool NonTieredCompPolicy::compare(CompileTask* task_x, CompileTask* task_y) {
350
351 if (task_x->weight() > task_y->weight()) {
352 return true;
353 }
354
355 return false;
356 }
357
358 void NonTieredCompPolicy::update_speed(jlong t, CompileTask* task) {
359 jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
360 jlong delta_t = t - task->prev_time();
361 Method* m = task->method();
362
363 int ic = m->interpreter_invocation_count();
364 int bc = m->backedge_count() + m->get_decay_counter();
365 int pre_ic = task->prev_ic_count();
366 int pre_bc = task->prev_bc_count();
367
368 int delta_e = (ic + bc) - (pre_ic + pre_bc);
369
370 if (delta_s >= MinUpdateTime) {
371 if (delta_t >= MinUpdateTime && delta_e > 0) {
372 task->set_prev_time(t);
373 task->set_prev_ic_count(ic);
374 task->set_prev_bc_count(bc);
375 int delta_n = FactorOfSizeScheduling * (ic - pre_ic) / 100 + 10 * (bc - pre_bc) / 100;
376 task->set_speed(delta_n * 1.0 / delta_t);
377 task->set_weight();
378 } else
379 if (delta_t > MaxUpdateTime && delta_e == 0) {
380 task->set_speed(0);
381 task->set_weight();
382 }
383 }
384 }
385
386 bool NonTieredCompPolicy::task_should_be_removed(jlong t, jlong timeout, CompileTask* task) {
387 jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
388 jlong delta_t = t - task->prev_time();
389 Method* m = task->method();
390
391 if (delta_t > timeout && delta_s > timeout) {
392 int ic = m->interpreter_invocation_count();
393 int bc = m->backedge_count() + m->get_decay_counter();
394
395 if(ic > InvocationOldThreshold || bc > LoopOldThreshold) {
396 // This task is old enough, do not remove it.
397 return false;
398 }
399
400 return task->speed() < 0.001;
401 }
402 return false;
403 }
404
405 #endif
406
407 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { 342 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) {
408 #ifndef MIPS64
409 return compile_queue->first(); 343 return compile_queue->first();
410 #else
411 CompileTask *max_task = NULL;
412 jlong t = os::javaTimeMillis();
413
414 int counter = 1;
415 for (CompileTask* task = compile_queue->first(); task != NULL;) {
416 CompileTask* next_task = task->next();
417 counter++;
418 if (counter > MaxCompileQueueSize) return max_task;
419 update_speed(t, task);
420 if (max_task == NULL) {
421 max_task = task;
422 } else {
423 if (task_should_be_removed(t, MinWatchTime, task)) {
424 CompileTaskWrapper ctw(task); // Frees the task
425 compile_queue->remove(task);
426 task->method()->clear_queued_for_compilation();
427 task = next_task;
428 continue;
429 }
430
431 if (compare(task, max_task)) {
432 max_task = task;
433 }
434 }
435 task = next_task;
436 }
437
438 return max_task;
439 #endif
440 } 344 }
441 345
442 bool NonTieredCompPolicy::is_mature(Method* method) { 346 bool NonTieredCompPolicy::is_mature(Method* method) {
443 MethodData* mdo = method->method_data(); 347 MethodData* mdo = method->method_data();
444 assert(mdo != NULL, "Should be"); 348 assert(mdo != NULL, "Should be");
456 360
457 nmethod* NonTieredCompPolicy::event(methodHandle method, methodHandle inlinee, int branch_bci, 361 nmethod* NonTieredCompPolicy::event(methodHandle method, methodHandle inlinee, int branch_bci,
458 int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) { 362 int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) {
459 assert(comp_level == CompLevel_none, "This should be only called from the interpreter"); 363 assert(comp_level == CompLevel_none, "This should be only called from the interpreter");
460 NOT_PRODUCT(trace_frequency_counter_overflow(method, branch_bci, bci)); 364 NOT_PRODUCT(trace_frequency_counter_overflow(method, branch_bci, bci));
461 #ifdef MIPS64
462 method->incr_num_of_requests(1);
463 #endif
464 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) { 365 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
465 // If certain JVMTI events (e.g. frame pop event) are requested then the 366 // If certain JVMTI events (e.g. frame pop event) are requested then the
466 // thread is forced to remain in interpreted code. This is 367 // thread is forced to remain in interpreted code. This is
467 // implemented partly by a check in the run_compiled_code 368 // implemented partly by a check in the run_compiled_code
468 // section of the interpreter whether we should skip running 369 // section of the interpreter whether we should skip running
561 // SimpleCompPolicy - compile current method 462 // SimpleCompPolicy - compile current method
562 463
563 void SimpleCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) { 464 void SimpleCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) {
564 const int comp_level = CompLevel_highest_tier; 465 const int comp_level = CompLevel_highest_tier;
565 const int hot_count = m->invocation_count(); 466 const int hot_count = m->invocation_count();
566 #ifdef MIPS64
567 const int bc = m->backedge_count();
568 #endif
569
570 reset_counter_for_invocation_event(m); 467 reset_counter_for_invocation_event(m);
571 #ifdef MIPS64
572 const int new_bc = m->backedge_count();
573 const int delta = bc - new_bc;
574 #endif
575 const char* comment = "count"; 468 const char* comment = "count";
576
577 #ifdef MIPS64
578 if(delta > 0) m->incr_decay_counter(delta);
579 #endif
580 469
581 if (is_compilation_enabled() && can_be_compiled(m, comp_level)) { 470 if (is_compilation_enabled() && can_be_compiled(m, comp_level)) {
582 nmethod* nm = m->code(); 471 nmethod* nm = m->code();
583 if (nm == NULL ) { 472 if (nm == NULL ) {
584 CompileBroker::compile_method(m, InvocationEntryBci, comp_level, m, hot_count, comment, thread); 473 CompileBroker::compile_method(m, InvocationEntryBci, comp_level, m, hot_count, comment, thread);

mercurial