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.mmtk.vm; 014 015import org.mmtk.policy.ImmortalSpace; 016 017import org.vmmagic.unboxed.*; 018import org.vmmagic.pragma.*; 019 020@Uninterruptible public abstract class Memory { 021 022 /** 023 * Allows for the VM to reserve space between HEAP_START() 024 * and AVAILABLE_START() for its own purposes. MMTk should 025 * expect to encounter objects in this range, but may not 026 * allocate in this range. 027 * 028 * MMTk expects the virtual address space between AVAILABLE_START() 029 * and AVAILABLE_END() to be contiguous and unmapped. 030 * Allows for the VM to reserve space between HEAP_END() 031 * and AVAILABLE_END() for its own purposes. MMTk should 032 * expect to encounter objects in this range, but may not 033 * allocate in this range. 034 * 035 * MMTk expects the virtual address space between AVAILABLE_START() 036 * and AVAILABLE_END() to be contiguous and unmapped. 037 * 038 * @return The high bound of the memory that MMTk can allocate. 039 */ 040 041 /** 042 * Return the space associated with/reserved for the VM. In the 043 * case of Jikes RVM this is the boot image space.<p> 044 * 045 * @return The space managed by the virtual machine. 046 */ 047 @Interruptible 048 public abstract ImmortalSpace getVMSpace(); 049 050 /** Global preparation for a collection. */ 051 public abstract void globalPrepareVMSpace(); 052 053 /** Per-collector preparation for a collection. */ 054 public abstract void collectorPrepareVMSpace(); 055 056 /** Per-collector post-collection work. */ 057 public abstract void collectorReleaseVMSpace(); 058 059 /** Global post-collection work. */ 060 public abstract void globalReleaseVMSpace(); 061 062 /** 063 * Sets the range of addresses associated with a heap. 064 * 065 * @param id the heap identifier 066 * @param start the address of the start of the heap 067 * @param end the address of the end of the heap 068 */ 069 public abstract void setHeapRange(int id, Address start, Address end); 070 071 /** 072 * Demand zero mmaps an area of virtual memory. 073 * 074 * @param start the address of the start of the area to be mapped 075 * @param size the size, in bytes, of the area to be mapped 076 * @return 0 if successful, otherwise the system errno 077 */ 078 public abstract int dzmmap(Address start, int size); 079 080 /** 081 * Protects access to an area of virtual memory. 082 * 083 * @param start the address of the start of the area to be mapped 084 * @param size the size, in bytes, of the area to be mapped 085 * @return <code>true</code> if successful, otherwise 086 * <code>false</code> 087 */ 088 public abstract boolean mprotect(Address start, int size); 089 090 /** 091 * Allows access to an area of virtual memory. 092 * 093 * @param start the address of the start of the area to be mapped 094 * @param size the size, in bytes, of the area to be mapped 095 * @return <code>true</code> if successful, otherwise 096 * <code>false</code> 097 */ 098 public abstract boolean munprotect(Address start, int size); 099 100 101 /** 102 * Zero a region of memory. 103 * 104 * @param useNT Use non temporal instructions (if available) 105 * @param start Start of address range (inclusive) 106 * @param len Length in bytes of range to zero 107 */ 108 public abstract void zero(boolean useNT, Address start, Extent len); 109 110 /** 111 * Logs the contents of an address and the surrounding memory to the 112 * error output. 113 * 114 * @param start the address of the memory to be dumped 115 * @param beforeBytes the number of bytes before the address to be 116 * included 117 * @param afterBytes the number of bytes after the address to be 118 * included 119 */ 120 public abstract void dumpMemory(Address start, int beforeBytes, 121 int afterBytes); 122 123 /** 124 * Wait for preceeding cache flush/invalidate instructions to complete 125 * on all processors. Ensures that all memory writes before this 126 * point are visible to all processors. 127 */ 128 @Inline 129 public abstract void sync(); 130 131 /** 132 * Wait for all preceeding instructions to complete and discard any 133 * prefetched instructions on this processor. Also prevents the 134 * compiler from performing code motion across this point. 135 */ 136 @Inline 137 public abstract void isync(); 138 139 /* 140 * NOTE: The following methods must be implemented by subclasses of this 141 * class, but are internal to the VM<->MM interface glue, so are never 142 * called by MMTk users. 143 */ 144 /** @return The lowest address in the virtual address space known to MMTk */ 145 protected abstract Address getHeapStartConstant(); 146 /** @return The highest address in the virtual address space known to MMTk */ 147 protected abstract Address getHeapEndConstant(); 148 /** @return The lowest address in the contiguous address space available to MMTk */ 149 protected abstract Address getAvailableStartConstant(); 150 /** @return The highest address in the contiguous address space available to MMTk */ 151 protected abstract Address getAvailableEndConstant(); 152 /** @return The log base two of the size of an address */ 153 protected abstract byte getLogBytesInAddressConstant(); 154 /** @return The log base two of the size of a word */ 155 protected abstract byte getLogBytesInWordConstant(); 156 /** @return The log base two of the size of an OS page */ 157 protected abstract byte getLogBytesInPageConstant(); 158 /** @return The log base two of the minimum allocation alignment */ 159 protected abstract byte getLogMinAlignmentConstant(); 160 /** @return The log base two of (MAX_ALIGNMENT/MIN_ALIGNMENT) */ 161 protected abstract byte getMaxAlignmentShiftConstant(); 162 /** @return The maximum number of bytes of padding to prepend to an object */ 163 protected abstract int getMaxBytesPaddingConstant(); 164 /** @return The value to store in alignment holes */ 165 protected abstract int getAlignmentValueConstant(); 166 167 /* 168 * NOTE: These methods should not be called by anything other than the 169 * reflective mechanisms in org.mmtk.vm.VM, and are not implemented by 170 * subclasses. This hack exists only to allow us to declare the respective 171 * methods as protected. 172 */ 173 static Address heapStartTrapdoor(Memory m) { 174 return m.getHeapStartConstant(); 175 } 176 static Address heapEndTrapdoor(Memory m) { 177 return m.getHeapEndConstant(); 178 } 179 static Address availableStartTrapdoor(Memory m) { 180 return m.getAvailableStartConstant(); 181 } 182 static Address availableEndTrapdoor(Memory m) { 183 return m.getAvailableEndConstant(); 184 } 185 static byte logBytesInAddressTrapdoor(Memory m) { 186 return m.getLogBytesInAddressConstant(); 187 } 188 static byte logBytesInWordTrapdoor(Memory m) { 189 return m.getLogBytesInWordConstant(); 190 } 191 static byte logBytesInPageTrapdoor(Memory m) { 192 return m.getLogBytesInPageConstant(); 193 } 194 static byte logMinAlignmentTrapdoor(Memory m) { 195 return m.getLogMinAlignmentConstant(); 196 } 197 static byte maxAlignmentShiftTrapdoor(Memory m) { 198 return m.getMaxAlignmentShiftConstant(); 199 } 200 static int maxBytesPaddingTrapdoor(Memory m) { 201 return m.getMaxBytesPaddingConstant(); 202 } 203 static int alignmentValueTrapdoor(Memory m) { 204 return m.getAlignmentValueConstant(); 205 } 206}