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.ia32; 014 015import static org.jikesrvm.ia32.RegisterConstants.THREAD_REGISTER; 016 017import org.jikesrvm.VM; 018import org.jikesrvm.compilers.common.assembler.ia32.Assembler; 019import org.jikesrvm.runtime.Magic; 020import org.jikesrvm.scheduler.RVMThread; 021import org.vmmagic.pragma.Uninterruptible; 022import org.vmmagic.unboxed.Offset; 023import org.jikesrvm.ia32.RegisterConstants.GPR; 024 025/** 026 * This class provides a layer of abstraction that the rest of the VM must 027 * use in order to access the current <code>RVMThread</code> object. 028 * 029 * @see RVMThread 030 */ 031public abstract class ThreadLocalState { 032 033 /** 034 * The C bootstrap program has placed a pointer to the initial 035 * RVMThread in ESI. 036 */ 037 @Uninterruptible 038 public 039 static void boot() { 040 // do nothing - everything is already set up. 041 } 042 043 @Uninterruptible 044 public static RVMThread getCurrentThread() { 045 return Magic.getESIAsThread(); 046 } 047 048 @Uninterruptible 049 public static void setCurrentThread(RVMThread p) { 050 Magic.setESIAsThread(p); 051 } 052 053 /** 054 * Emit an instruction sequence to load current RVMThread 055 * object from a location defined by [base]+offset 056 * 057 * @param asm assembler object 058 * @param base number of base register 059 * @param offset offset 060 */ 061 public static void emitLoadThread(Assembler asm, GPR base, Offset offset) { 062 if (VM.BuildFor32Addr) { 063 asm.emitMOV_Reg_RegDisp(THREAD_REGISTER, base, offset); 064 } else { 065 asm.emitMOV_Reg_RegDisp_Quad(THREAD_REGISTER, base, offset); 066 } 067 } 068} 069