-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b851b21
Showing
9 changed files
with
579 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Decide on the file for output | ||
# | ||
N=`cat count 2>/dev/null` | ||
if [ "$N" == "" ] | ||
then | ||
N=2 | ||
fi | ||
N=$((N + 1)) | ||
echo $N > count | ||
FILE=output-$N.txt | ||
unset _JAVA_OPTIONS | ||
echo Output will go to $FILE... | ||
sleep 3 | ||
|
||
# | ||
# Prepare the command line | ||
# | ||
#PRINT_COMPILATION="-XX:+PrintCompilation" | ||
#PRINT_INLINING="-XX:+PrintInlining" | ||
#PRINT_ASSEMBLY="-XX:+PrintOptoAssembly" | ||
#TRACE_DEOPT="-XX:+TraceDeoptimization" | ||
#PROF_TRAPS="-XX:+ProfileTraps" | ||
OTHERS="-XX:+TraceICs -XX:+TraceInlineCacheClearing" | ||
JAVA_OPTS="-Xms2g \ | ||
-Xmx2g \ | ||
-Xss4m \ | ||
-XX:MaxPermSize=512M \ | ||
-XX:ReservedCodeCacheSize=256m \ | ||
-XX:+UseParallelGC \ | ||
-XX:PermSize=256m \ | ||
-XX:+UseNUMA \ | ||
-XX:-TieredCompilation \ | ||
-XX:+UnlockDiagnosticVMOptions \ | ||
$PRINT_COMPILATION \ | ||
$PRINT_INLINING \ | ||
$TRACE_DEOPT \ | ||
$PRINT_ASSEMBLY \ | ||
$PROF_TRAPSi | ||
$OTHERS" | ||
CMD="java -server -cp lib/scala-library.jar:exp.jar $JAVA_OPTS miniboxing.test.TestJVM" | ||
|
||
# | ||
# Run and store results | ||
# | ||
echo -e "$CMD\n\n\n" > $FILE | ||
$CMD 2>&1 | tee -a $FILE |
192 changes: 192 additions & 0 deletions
192
src/miniboxing/benchmarks/hardcoded/MBResizableArray.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
package miniboxing.benchmarks.hardcoded | ||
|
||
import miniboxing.runtime.MiniboxArray._ | ||
import miniboxing.runtime.MiniboxConversions._ | ||
import miniboxing.runtime.MiniboxArray | ||
import scala.Int.int2long | ||
|
||
/* | ||
* The arrays are tricky since we need to use the natural representation for them. | ||
* | ||
* The plugin if arrays are used inside minispeced code according to the following rules: | ||
* - every array creation is done via: MiniboxArray.newArray[T](len) | ||
* - every access to the array requires a cast to its type: array.asInstanceOf[Array[T]](p) | ||
* - local array variables are not supported | ||
*/ | ||
trait MBResizableArray[T] { | ||
// fields | ||
def initialSize: Int // getter | ||
def initialSize_J: Int // getter (specialized) | ||
|
||
def size: Int // getter | ||
def size_=(newSize: Int): Unit // setter | ||
def size_J: Int // getter (specialized) | ||
def size_J_=(newSize: Int): Unit // setter (specialized) | ||
|
||
def elemCount: Int // getter | ||
def elemCount_=(newElemCount: Int): Unit // setter | ||
def elemCount_J: Int // getter (specialized) | ||
def elemCount_J_=(newElemCount: Int): Unit // setter (specialized) | ||
|
||
def array: Any // getter | ||
def array_=(newArray: Any): Unit // setter | ||
def array_J: Any // getter (specialized) | ||
def array_J_=(newArray: Any): Unit // setter (specialized) | ||
|
||
def newarray: Any // getter | ||
def newarray_=(newNewArray: Any): Unit // setter | ||
def newarray_J: Any // getter (specialized) | ||
def newarray_J_=(newNewArray: Any): Unit // setter (specialized) | ||
|
||
// methods | ||
// extend | ||
def extend(): Unit | ||
def extend_J(): Unit | ||
|
||
// add | ||
def add(elem: T) | ||
def add_J(elem: Long) | ||
|
||
// reverse | ||
def reverse(): Unit | ||
def reverse_J(): Unit | ||
|
||
// contains | ||
def contains(elem: T): Boolean | ||
def contains_J(elem: Long): Boolean | ||
|
||
// length | ||
def length: Int | ||
def length_J: Int | ||
|
||
// setElement | ||
def setElement(p: Int, t: T): Unit | ||
def setElement_J(p: Int, t: Long): Unit | ||
|
||
// getElement | ||
def getElement(p: Int): T | ||
def getElement_J(p: Int): Long | ||
|
||
// toString | ||
def toString(): String | ||
def toString_J(): String | ||
} | ||
|
||
class MBResizableArray_J[Tsp: Manifest](T_TypeTag: Byte) extends MBResizableArray[Tsp] { | ||
// initialSize | ||
private[this] final val _initialSize_J = 4 | ||
def initialSize: Int = initialSize_J | ||
def initialSize_J: Int = _initialSize_J | ||
|
||
// size | ||
private[this] var _size_J: Int = initialSize_J | ||
def size: Int = size_J | ||
def size_=(newSize: Int): Unit = size_J_=(newSize) | ||
def size_J: Int = _size_J | ||
def size_J_=(newSize: Int): Unit = _size_J = newSize | ||
|
||
private[this] var _elemCount_J: Int = 0 | ||
def elemCount: Int = elemCount_J | ||
def elemCount_=(newElemCount: Int): Unit = elemCount_J_=(newElemCount) | ||
def elemCount_J: Int = _elemCount_J | ||
def elemCount_J_=(newElemCount: Int): Unit = _elemCount_J = newElemCount | ||
|
||
private[this] var _array_J: Any = mbarray_new(initialSize, T_TypeTag) | ||
def array: Any = array_J | ||
def array_=(newArray: Any): Unit = array_J_=(newArray) | ||
def array_J: Any = _array_J | ||
def array_J_=(newArray: Any): Unit = _array_J = newArray | ||
|
||
private[this] var _newarray_J: Any = null | ||
def newarray: Any = _newarray_J | ||
def newarray_=(newNewArray: Any): Unit = newarray_J_=(newNewArray) | ||
def newarray_J: Any = _newarray_J | ||
def newarray_J_=(newNewArray: Any): Unit = _newarray_J = newNewArray | ||
|
||
|
||
// methods | ||
// extend | ||
def extend(): Unit = extend_J | ||
def extend_J(): Unit = { | ||
if (elemCount_J == size_J) { | ||
var pos = 0 | ||
newarray_J = mbarray_new(2 * size, T_TypeTag)// new Array[Tsp](2 * size) | ||
while(pos < size_J) { | ||
// newarray.asInstanceOf[Array[Tsp]](pos) = array.asInstanceOf[Array[Tsp]](pos) | ||
mbarray_update_minibox(newarray_J, pos, mbarray_apply_minibox(array_J, pos, T_TypeTag), T_TypeTag) | ||
pos += 1 | ||
} | ||
array_J = newarray_J | ||
size_J *= 2 | ||
} | ||
} | ||
|
||
|
||
// add | ||
def add(elem: Tsp) = add_J(box2minibox(elem)) | ||
def add_J(elem: Long) = { | ||
extend_J() | ||
//array.asInstanceOf[Array[Tsp]](elemCount) = elem | ||
mbarray_update_minibox(array_J, elemCount_J, elem, T_TypeTag) | ||
elemCount_J += 1 | ||
} | ||
|
||
|
||
|
||
// reverse | ||
def reverse(): Unit = reverse_J() | ||
def reverse_J(): Unit = { | ||
var pos = 0 | ||
while (pos * 2 < elemCount_J) { | ||
val tmp1: Long = getElement_J(pos) | ||
val tmp2: Long = getElement_J(elemCount_J-pos-1) | ||
setElement_J(pos, tmp2) | ||
setElement_J(elemCount_J-pos-1, tmp1) | ||
pos += 1 | ||
} | ||
} | ||
|
||
|
||
// contains | ||
def contains(elem: Tsp): Boolean = contains_J(box2minibox(elem)) | ||
def contains_J(elem: Long): Boolean = { | ||
// var pos = 0 | ||
// while (pos < elemCount_J){ | ||
// if (mboxed_eqeq(getElement_J(pos), elem)) | ||
// return true | ||
// pos += 1 | ||
// } | ||
return false | ||
} | ||
|
||
// length | ||
def length: Int = length_J | ||
def length_J: Int = elemCount_J | ||
|
||
// setElement | ||
@inline final def setElement(p: Int, t: Tsp): Unit = setElement_J(p, box2minibox(t)) | ||
@inline final def setElement_J(p: Int, t: Long) = { | ||
//array.asInstanceOf[Array[Tsp]](p) = t | ||
mbarray_update_minibox(array_J, p, t, T_TypeTag) | ||
} | ||
|
||
// getElement | ||
@inline final def getElement(p: Int): Tsp = minibox2box(getElement_J(p), T_TypeTag) | ||
@inline final def getElement_J(p: Int): Long = { | ||
// array.asInstanceOf[Array[Tsp]](p) | ||
mbarray_apply_minibox(array_J, p, T_TypeTag) | ||
} | ||
|
||
// toString | ||
override def toString(): String = toString_J() | ||
def toString_J(): String = { | ||
// var pos = 0 | ||
// var ret = "" | ||
// while (pos < elemCount_J) { | ||
// ret += mboxed_toString(getElement_J(pos), T_TypeTag) + ", " | ||
// pos += 1 | ||
// } | ||
// ret | ||
"" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package miniboxing.runtime | ||
import MiniboxTypes._ | ||
//import MiniboxConstants._ | ||
import MiniboxConversions._ | ||
|
||
// TODO: Can we use Array[T] and rely on Scala to erase the types? | ||
object MiniboxArray { | ||
|
||
// import MiniboxConstants._ | ||
// instead of importing, we copy the values here so the Scala compiler transforms the calls into tableswitches | ||
// private[this] final val UNIT = 0; | ||
// private[this] final val BOOLEAN = 1; | ||
// private[this] final val BYTE = 2; | ||
// private[this] final val SHORT = 3; | ||
// private[this] final val CHAR = 4; | ||
// private[this] final val INT = 5; | ||
// private[this] final val LONG = 6; | ||
// private[this] final val FLOAT = 7; | ||
// private[this] final val DOUBLE = 8; | ||
// private[this] final val REFERENCE = 9; | ||
|
||
@inline final def mbarray_new(len: Int, tag: Tag): Any = | ||
tag.asInstanceOf[Byte] match { | ||
// See https://issues.scala-lang.org/browse/SI-6956 | ||
case 0 /* UNIT */ => new Array[Unit](len) | ||
case 1 /* BOOLEAN */ => new Array[Boolean](len) | ||
case 2 /* BYTE */ => new Array[Byte](len) | ||
case 3 /* CHAR */ => new Array[Char](len) | ||
case 4 /* SHORT */ => new Array[Short](len) | ||
case 5 /* INT */ => new Array[Int](len) | ||
case 6 /* LONG */ => new Array[Long](len) | ||
case 7 /* FLOAT */ => new Array[Float](len) | ||
case 8 /* DOUBLE */ => new Array[Double](len) | ||
} | ||
|
||
@inline final def mbarray_apply_minibox(array: Any, idx: Int, tag: Tag): Minibox = { | ||
// array match { | ||
// case a: Array[Any] => box2minibox(a(idx)) | ||
// case _ => | ||
tag.asInstanceOf[Byte] match { | ||
// See https://issues.scala-lang.org/browse/SI-6956 | ||
case 0 /* UNIT */ => array.asInstanceOf[Array[Unit]](idx); 0 | ||
case 1 /* BOOLEAN */ => if (array.asInstanceOf[Array[Boolean]](idx)) 1 else 0 | ||
case 2 /* BYTE */ => array.asInstanceOf[Array[Byte]](idx).toLong | ||
case 3 /* CHAR */ => array.asInstanceOf[Array[Char]](idx).toLong | ||
case 4 /* SHORT */ => array.asInstanceOf[Array[Short]](idx).toLong | ||
case 5 /* INT */ => array.asInstanceOf[Array[Int]](idx).toLong | ||
case 6 /* LONG */ => array.asInstanceOf[Array[Long]](idx) | ||
case 7 /* FLOAT */ => java.lang.Float.floatToRawIntBits(array.asInstanceOf[Array[Float]](idx)).toLong | ||
case 8 /* DOUBLE */ => java.lang.Double.doubleToRawLongBits(array.asInstanceOf[Array[Double]](idx)).toLong | ||
} | ||
// } | ||
} | ||
|
||
@inline final def mbarray_apply_box[T](array: Any, idx: Int, tag: Tag): T = { | ||
// array match { | ||
// case a: Array[Any] => a(idx).asInstanceOf[T] | ||
// case _ => | ||
val result = tag.asInstanceOf[Byte] match { | ||
// See https://issues.scala-lang.org/browse/SI-6956 | ||
case 0 /* UNIT */ => array.asInstanceOf[Array[Unit]](idx) = 0 | ||
case 1 /* BOOLEAN */ => array.asInstanceOf[Array[Boolean]](idx) | ||
case 2 /* BYTE */ => array.asInstanceOf[Array[Byte]](idx) | ||
case 3 /* CHAR */ => array.asInstanceOf[Array[Char]](idx) | ||
case 4 /* SHORT */ => array.asInstanceOf[Array[Short]](idx) | ||
case 5 /* INT */ => array.asInstanceOf[Array[Int]](idx) | ||
case 6 /* LONG */ => array.asInstanceOf[Array[Long]](idx) | ||
case 7 /* FLOAT */ => array.asInstanceOf[Array[Float]](idx) | ||
case 8 /* DOUBLE */ => array.asInstanceOf[Array[Double]](idx) | ||
} | ||
result.asInstanceOf[T] | ||
// } | ||
} | ||
|
||
@inline final def mbarray_update_minibox(array: Any, idx: Int, value: Minibox, tag: Tag): Unit = { | ||
// array match { | ||
// case a: Array[Any] => a(idx) = minibox2box(value, tag) | ||
// case _ => | ||
tag.asInstanceOf[Byte] match { | ||
// See https://issues.scala-lang.org/browse/SI-6956 | ||
case 0 /* UNIT */ => array.asInstanceOf[Array[Unit]](idx) = () | ||
case 1 /* BOOLEAN */ => array.asInstanceOf[Array[Boolean]](idx) = if (value == 0) false else true | ||
case 2 /* BYTE */ => array.asInstanceOf[Array[Byte]](idx) = value.toByte | ||
case 3 /* CHAR */ => array.asInstanceOf[Array[Char]](idx) = value.toChar | ||
case 4 /* SHORT */ => array.asInstanceOf[Array[Short]](idx) = value.toShort | ||
case 5 /* INT */ => array.asInstanceOf[Array[Int]](idx) = value.toInt | ||
case 6 /* LONG */ => array.asInstanceOf[Array[Long]](idx) = value | ||
case 7 /* FLOAT */ => array.asInstanceOf[Array[Float]](idx) = java.lang.Float.intBitsToFloat(value.toInt) | ||
case 8 /* DOUBLE */ => array.asInstanceOf[Array[Double]](idx) = java.lang.Double.longBitsToDouble(value) | ||
} | ||
// } | ||
} | ||
|
||
@inline final def mbarray_update_box[T](array: Any, idx: Int, value: T, tag: Tag): Unit = { | ||
// array match { | ||
// case a: Array[Any] => a(idx) = value | ||
// case _ => | ||
tag.asInstanceOf[Byte] match { | ||
// See https://issues.scala-lang.org/browse/SI-6956 | ||
case 0 /* UNIT */ => array.asInstanceOf[Array[Unit]](idx) = value.asInstanceOf[Unit] | ||
case 1 /* BOOLEAN */ => array.asInstanceOf[Array[Boolean]](idx) = value.asInstanceOf[Boolean] | ||
case 2 /* BYTE */ => array.asInstanceOf[Array[Byte]](idx) = value.asInstanceOf[Byte] | ||
case 3 /* CHAR */ => array.asInstanceOf[Array[Char]](idx) = value.asInstanceOf[Char] | ||
case 4 /* SHORT */ => array.asInstanceOf[Array[Short]](idx) = value.asInstanceOf[Short] | ||
case 5 /* INT */ => array.asInstanceOf[Array[Int]](idx) = value.asInstanceOf[Int] | ||
case 6 /* LONG */ => array.asInstanceOf[Array[Long]](idx) = value.asInstanceOf[Long] | ||
case 7 /* FLOAT */ => array.asInstanceOf[Array[Float]](idx) = value.asInstanceOf[Float] | ||
case 8 /* DOUBLE */ => array.asInstanceOf[Array[Double]](idx) = value.asInstanceOf[Double] | ||
} | ||
// } | ||
} | ||
|
||
@inline final def mbarray_length(array: Any, tag: Tag): Int = | ||
// array match { | ||
// case a: Array[Any] => a.length | ||
// case _ => | ||
tag.asInstanceOf[Byte] match { | ||
// See https://issues.scala-lang.org/browse/SI-6956 | ||
case 0 /* UNIT */ => array.asInstanceOf[Array[Unit]].length | ||
case 1 /* BOOLEAN */ => array.asInstanceOf[Array[Boolean]].length | ||
case 2 /* BYTE */ => array.asInstanceOf[Array[Byte]].length | ||
case 3 /* CHAR */ => array.asInstanceOf[Array[Char]].length | ||
case 4 /* SHORT */ => array.asInstanceOf[Array[Short]].length | ||
case 5 /* INT */ => array.asInstanceOf[Array[Int]].length | ||
case 6 /* LONG */ => array.asInstanceOf[Array[Long]].length | ||
case 7 /* FLOAT */ => array.asInstanceOf[Array[Float]].length | ||
case 8 /* DOUBLE */ => array.asInstanceOf[Array[Double]].length | ||
} | ||
// } | ||
} |
Oops, something went wrong.