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 */ 013 package org.jikesrvm.classloader; 014 015 import org.jikesrvm.mm.mminterface.MemoryManager; 016 017 import org.jikesrvm.VM; 018 019 /** 020 * The manager of specialized methods. 021 */ 022 public final class SpecializedMethodManager { 023 /** The number of specialized methods. Currently the MM is the only consumer. */ 024 private static final int numSpecializedMethods = MemoryManager.numSpecializedMethods(); 025 026 /** All the specialized methods */ 027 private static final SpecializedMethod[] methods = new SpecializedMethod[numSpecializedMethods]; 028 029 /** The number of specialized methods */ 030 public static int numSpecializedMethods() { return numSpecializedMethods; } 031 032 /** Set up the specialized methods for the given type */ 033 public static void notifyTypeInstantiated(RVMType type) { 034 for(int i=0; i < numSpecializedMethods; i++) { 035 if (methods[i] == null) { 036 initializeSpecializedMethod(i); 037 } 038 type.setSpecializedMethod(i, methods[i].specializeMethod(type)); 039 } 040 } 041 042 /** Set up the specialized methods for the given type */ 043 public static void refreshSpecializedMethods(RVMType type) { 044 for(int i=0; i < numSpecializedMethods; i++) { 045 if (VM.VerifyAssertions) VM._assert(methods[i] != null, "Specialized method missing!"); 046 type.setSpecializedMethod(i, methods[i].specializeMethod(type)); 047 } 048 } 049 050 /** Ensure that a specific specialized method now exists. */ 051 private static void initializeSpecializedMethod(int id) { 052 if (VM.VerifyAssertions) VM._assert(id >= 0); 053 if (VM.VerifyAssertions) VM._assert(id < numSpecializedMethods); 054 if (VM.VerifyAssertions) VM._assert(methods[id] == null); 055 methods[id] = MemoryManager.createSpecializedMethod(id); 056 } 057 058 /** Can not create an instance of the manager */ 059 private SpecializedMethodManager() {} 060 }