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.mmtk.utility.heap; 014 015 import org.mmtk.utility.Constants; 016 017 import org.vmmagic.unboxed.*; 018 019 /** 020 * This class manages the encoding and decoding of virtual memory requests.<p> 021 * 022 * By encapsulating this aspect of the construction of a space, we greatly 023 * reduce the number of constructors required. 024 */ 025 public final class VMRequest implements Constants { 026 027 public static final int REQUEST_DISCONTIGUOUS = 0; 028 public static final int REQUEST_FIXED = 1; 029 public static final int REQUEST_EXTENT = 3; 030 public static final int REQUEST_FRACTION = 4; 031 032 public final int type; 033 public final Address start; 034 public final Extent extent; 035 public final float frac; 036 public final boolean top; 037 038 private VMRequest(int type, Address start, Extent bytes, float frac, boolean top) { 039 this.type = type; 040 this.start = start; 041 this.extent = bytes; 042 this.frac = frac; 043 this.top = top; 044 } 045 046 /** 047 * Is this a discontiguous space request? 048 * @return true if this is a discontiguous space request, false otherwise 049 */ 050 public boolean isDiscontiguous() { 051 return type == REQUEST_DISCONTIGUOUS; 052 } 053 054 /** 055 * A request for a discontiguous region of memory 056 * 057 * @return The request object 058 */ 059 public static VMRequest create() { 060 return new VMRequest(REQUEST_DISCONTIGUOUS, Address.zero(), Extent.zero(), 0f, false); 061 } 062 063 /** 064 * A request for an explicit region of memory 065 * 066 * @param start The start of the region 067 * @param extent The size of the region 068 * @return The request object 069 */ 070 public static VMRequest create(Address start, Extent extent) { 071 return new VMRequest(REQUEST_FIXED, start, extent, 0f, false); 072 } 073 074 /** 075 * A request for a number of megabytes of memory 076 * 077 * @param mb The number of megabytes 078 * @return The request object 079 */ 080 public static VMRequest create(int mb) { 081 return create(mb, false); 082 } 083 084 /** 085 * A request for a fraction of available memory 086 * 087 * @param frac The fraction 088 * @return The request object 089 */ 090 public static VMRequest create(float frac) { 091 return create(frac, false); 092 } 093 094 /** 095 * A request for a number of megabytes of memory, optionally requesting the highest available. 096 * 097 * @param mb The number of megabytes 098 * @param top True to request high memory 099 * @return The request object 100 */ 101 public static VMRequest create(int mb, boolean top) { 102 return new VMRequest(REQUEST_EXTENT, Address.zero(), Word.fromIntSignExtend(mb).lsh(LOG_BYTES_IN_MBYTE).toExtent(), 0f, top); 103 } 104 105 /** 106 * A request for a fraction of available memory, optionally requesting the highest available. 107 * 108 * @param frac The fraction 109 * @param top True to request high memory 110 * @return The request object 111 */ 112 public static VMRequest create(float frac, boolean top) { 113 return new VMRequest(REQUEST_FRACTION, Address.zero(), Extent.zero(), frac, top); 114 } 115 116 /** 117 * A request for a number of bytes of memory, optionally requesting the highest available. 118 * 119 * @param extent The number of bytes 120 * @param top True to request high memory 121 * @return The request object 122 */ 123 public static VMRequest create(Extent extent, boolean top) { 124 return new VMRequest(REQUEST_EXTENT, Address.zero(), extent, 0f, top); 125 } 126 }