001/* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013package org.jikesrvm.adaptive.recompilation; 014 015import org.jikesrvm.adaptive.OnStackReplacementPlan; 016import org.jikesrvm.adaptive.controller.Controller; 017import org.jikesrvm.adaptive.controller.ControllerPlan; 018import org.jikesrvm.scheduler.SystemThread; 019import org.vmmagic.pragma.NonMoving; 020 021/** 022 * This class is a separate thread whose job is to monitor a (priority) 023 * queue of compilation plans. Whenever the queue is nonempty, this 024 * thread will pick the highest priority compilation plan from the queue 025 * and invoke the OPT compiler to perform the plan. 026 * <p> 027 * No intelligence is contained in this class. All policy decisions are 028 * made by the ControllerThread. 029 */ 030@NonMoving 031public final class CompilationThread extends SystemThread { 032 033 /** 034 * constructor 035 */ 036 public CompilationThread() { 037 super("CompilationThread"); 038 } 039 040 /** 041 * This is the main loop of the compilation thread. Its job is to 042 * remove controller plans from the compilation queue and perform 043 * them. 044 */ 045 @Override 046 public void run() { 047 // Make a blocking call to deleteMin to get a plan and then execute it. 048 // Repeat... 049 while (true) { 050 Object plan = Controller.compilationQueue.deleteMin(); 051 if (plan instanceof ControllerPlan) { 052 ((ControllerPlan) plan).doRecompile(); 053 } else if (plan instanceof OnStackReplacementPlan) { 054 ((OnStackReplacementPlan) plan).execute(); 055 } 056 } 057 } 058 059} 060