Skip to content

Commit 8257e8a

Browse files
committed
Add frozen compiler snapshot to bench
The idea is that we have a stable base on which to test performance
1 parent ab2210c commit 8257e8a

File tree

430 files changed

+128454
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

430 files changed

+128454
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package dottyBench.tools
2+
3+
case class FatalError(msg: String) extends Exception(msg)
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
package dottyBench.tools
2+
package backend
3+
4+
object ScalaPrimitivesOps extends ScalaPrimitivesOps
5+
6+
class ScalaPrimitivesOps {
7+
// Arithmetic unary operations
8+
final val POS = 1 // +x
9+
final val NEG = 2 // -x
10+
final val NOT = 3 // ~x
11+
12+
// Arithmetic binary operations
13+
final val ADD = 10 // x + y
14+
final val SUB = 11 // x - y
15+
final val MUL = 12 // x * y
16+
final val DIV = 13 // x / y
17+
final val MOD = 14 // x % y
18+
19+
// Bitwise operations
20+
final val OR = 20 // x | y
21+
final val XOR = 21 // x ^ y
22+
final val AND = 22 // x & y
23+
24+
// Shift operations
25+
final val LSL = 30 // x << y
26+
final val LSR = 31 // x >>> y
27+
final val ASR = 32 // x >> y
28+
29+
// Comparison operations
30+
final val ID = 40 // x eq y
31+
final val NI = 41 // x ne y
32+
final val EQ = 42 // x == y
33+
final val NE = 43 // x != y
34+
final val LT = 44 // x < y
35+
final val LE = 45 // x <= y
36+
final val GT = 46 // x > y
37+
final val GE = 47 // x >= y
38+
39+
// Boolean unary operations
40+
final val ZNOT = 50 // !x
41+
42+
// Boolean binary operations
43+
final val ZOR = 60 // x || y
44+
final val ZAND = 61 // x && y
45+
46+
// Array operations
47+
final val LENGTH = 70 // x.length
48+
final val APPLY = 71 // x(y)
49+
final val UPDATE = 72 // x(y) = z
50+
51+
// Any operations
52+
final val IS = 80 // x.is[y]
53+
final val AS = 81 // x.as[y]
54+
final val HASH = 87 // x.##
55+
56+
// AnyRef operations
57+
final val SYNCHRONIZED = 90 // x.synchronized(y)
58+
59+
// String operations
60+
final val CONCAT = 100 // String.valueOf(x)+String.valueOf(y)
61+
62+
// coercions
63+
final val COERCE = 101
64+
65+
// RunTime operations
66+
final val BOX = 110 // RunTime.box_<X>(x)
67+
final val UNBOX = 111 // RunTime.unbox_<X>(x)
68+
final val NEW_ZARRAY = 112 // RunTime.zarray(x)
69+
final val NEW_BARRAY = 113 // RunTime.barray(x)
70+
final val NEW_SARRAY = 114 // RunTime.sarray(x)
71+
final val NEW_CARRAY = 115 // RunTime.carray(x)
72+
final val NEW_IARRAY = 116 // RunTime.iarray(x)
73+
final val NEW_LARRAY = 117 // RunTime.larray(x)
74+
final val NEW_FARRAY = 118 // RunTime.farray(x)
75+
final val NEW_DARRAY = 119 // RunTime.darray(x)
76+
final val NEW_OARRAY = 120 // RunTime.oarray(x)
77+
78+
final val ZARRAY_LENGTH = 131 // RunTime.zarray_length(x)
79+
final val BARRAY_LENGTH = 132 // RunTime.barray_length(x)
80+
final val SARRAY_LENGTH = 133 // RunTime.sarray_length(x)
81+
final val CARRAY_LENGTH = 134 // RunTime.carray_length(x)
82+
final val IARRAY_LENGTH = 135 // RunTime.iarray_length(x)
83+
final val LARRAY_LENGTH = 136 // RunTime.larray_length(x)
84+
final val FARRAY_LENGTH = 137 // RunTime.farray_length(x)
85+
final val DARRAY_LENGTH = 138 // RunTime.darray_length(x)
86+
final val OARRAY_LENGTH = 139 // RunTime.oarray_length(x)
87+
88+
final val ZARRAY_GET = 140 // RunTime.zarray_get(x,y)
89+
final val BARRAY_GET = 141 // RunTime.barray_get(x,y)
90+
final val SARRAY_GET = 142 // RunTime.sarray_get(x,y)
91+
final val CARRAY_GET = 143 // RunTime.carray_get(x,y)
92+
final val IARRAY_GET = 144 // RunTime.iarray_get(x,y)
93+
final val LARRAY_GET = 145 // RunTime.larray_get(x,y)
94+
final val FARRAY_GET = 146 // RunTime.farray_get(x,y)
95+
final val DARRAY_GET = 147 // RunTime.darray_get(x,y)
96+
final val OARRAY_GET = 148 // RunTime.oarray_get(x,y)
97+
98+
final val ZARRAY_SET = 150 // RunTime.zarray(x,y,z)
99+
final val BARRAY_SET = 151 // RunTime.barray(x,y,z)
100+
final val SARRAY_SET = 152 // RunTime.sarray(x,y,z)
101+
final val CARRAY_SET = 153 // RunTime.carray(x,y,z)
102+
final val IARRAY_SET = 154 // RunTime.iarray(x,y,z)
103+
final val LARRAY_SET = 155 // RunTime.larray(x,y,z)
104+
final val FARRAY_SET = 156 // RunTime.farray(x,y,z)
105+
final val DARRAY_SET = 157 // RunTime.darray(x,y,z)
106+
final val OARRAY_SET = 158 // RunTime.oarray(x,y,z)
107+
108+
final val B2B = 200 // RunTime.b2b(x)
109+
final val B2S = 201 // RunTime.b2s(x)
110+
final val B2C = 202 // RunTime.b2c(x)
111+
final val B2I = 203 // RunTime.b2i(x)
112+
final val B2L = 204 // RunTime.b2l(x)
113+
final val B2F = 205 // RunTime.b2f(x)
114+
final val B2D = 206 // RunTime.b2d(x)
115+
116+
final val S2B = 210 // RunTime.s2b(x)
117+
final val S2S = 211 // RunTime.s2s(x)
118+
final val S2C = 212 // RunTime.s2c(x)
119+
final val S2I = 213 // RunTime.s2i(x)
120+
final val S2L = 214 // RunTime.s2l(x)
121+
final val S2F = 215 // RunTime.s2f(x)
122+
final val S2D = 216 // RunTime.s2d(x)
123+
124+
final val C2B = 220 // RunTime.c2b(x)
125+
final val C2S = 221 // RunTime.c2s(x)
126+
final val C2C = 222 // RunTime.c2c(x)
127+
final val C2I = 223 // RunTime.c2i(x)
128+
final val C2L = 224 // RunTime.c2l(x)
129+
final val C2F = 225 // RunTime.c2f(x)
130+
final val C2D = 226 // RunTime.c2d(x)
131+
132+
final val I2B = 230 // RunTime.i2b(x)
133+
final val I2S = 231 // RunTime.i2s(x)
134+
final val I2C = 232 // RunTime.i2c(x)
135+
final val I2I = 233 // RunTime.i2i(x)
136+
final val I2L = 234 // RunTime.i2l(x)
137+
final val I2F = 235 // RunTime.i2f(x)
138+
final val I2D = 236 // RunTime.i2d(x)
139+
140+
final val L2B = 240 // RunTime.l2b(x)
141+
final val L2S = 241 // RunTime.l2s(x)
142+
final val L2C = 242 // RunTime.l2c(x)
143+
final val L2I = 243 // RunTime.l2i(x)
144+
final val L2L = 244 // RunTime.l2l(x)
145+
final val L2F = 245 // RunTime.l2f(x)
146+
final val L2D = 246 // RunTime.l2d(x)
147+
148+
final val F2B = 250 // RunTime.f2b(x)
149+
final val F2S = 251 // RunTime.f2s(x)
150+
final val F2C = 252 // RunTime.f2c(x)
151+
final val F2I = 253 // RunTime.f2i(x)
152+
final val F2L = 254 // RunTime.f2l(x)
153+
final val F2F = 255 // RunTime.f2f(x)
154+
final val F2D = 256 // RunTime.f2d(x)
155+
156+
final val D2B = 260 // RunTime.d2b(x)
157+
final val D2S = 261 // RunTime.d2s(x)
158+
final val D2C = 262 // RunTime.d2c(x)
159+
final val D2I = 263 // RunTime.d2i(x)
160+
final val D2L = 264 // RunTime.d2l(x)
161+
final val D2F = 265 // RunTime.d2f(x)
162+
final val D2D = 266 // RunTime.d2d(x)
163+
164+
/** Check whether the given operation code is an array operation. */
165+
def isArrayOp(code: Int): Boolean =
166+
isArrayNew(code) | isArrayLength(code) | isArrayGet(code) | isArraySet(code)
167+
168+
def isArrayNew(code: Int): Boolean = code match {
169+
case NEW_ZARRAY | NEW_BARRAY | NEW_SARRAY | NEW_CARRAY |
170+
NEW_IARRAY | NEW_LARRAY | NEW_FARRAY | NEW_DARRAY |
171+
NEW_OARRAY => true
172+
case _ => false
173+
}
174+
175+
def isArrayLength(code: Int): Boolean = code match {
176+
case ZARRAY_LENGTH | BARRAY_LENGTH | SARRAY_LENGTH | CARRAY_LENGTH |
177+
IARRAY_LENGTH | LARRAY_LENGTH | FARRAY_LENGTH | DARRAY_LENGTH |
178+
OARRAY_LENGTH | LENGTH => true
179+
case _ => false
180+
}
181+
182+
def isArrayGet(code: Int): Boolean = code match {
183+
case ZARRAY_GET | BARRAY_GET | SARRAY_GET | CARRAY_GET |
184+
IARRAY_GET | LARRAY_GET | FARRAY_GET | DARRAY_GET |
185+
OARRAY_GET | APPLY => true
186+
case _ => false
187+
}
188+
189+
def isArraySet(code: Int): Boolean = code match {
190+
case ZARRAY_SET | BARRAY_SET | SARRAY_SET | CARRAY_SET |
191+
IARRAY_SET | LARRAY_SET | FARRAY_SET | DARRAY_SET |
192+
OARRAY_SET | UPDATE => true
193+
case _ => false
194+
}
195+
196+
/** Check whether the given code is a comparison operator */
197+
def isComparisonOp(code: Int): Boolean = code match {
198+
case ID | NI | EQ | NE |
199+
LT | LE | GT | GE => true
200+
201+
case _ => false
202+
}
203+
def isUniversalEqualityOp(code: Int): Boolean = (code == EQ) || (code == NE)
204+
def isReferenceEqualityOp(code: Int): Boolean = (code == ID) || (code == NI)
205+
206+
def isArithmeticOp(code: Int): Boolean = code match {
207+
case POS | NEG | NOT => true; // unary
208+
case ADD | SUB | MUL |
209+
DIV | MOD => true; // binary
210+
case OR | XOR | AND |
211+
LSL | LSR | ASR => true; // bitwise
212+
case _ => false
213+
}
214+
215+
def isLogicalOp(code: Int): Boolean = code match {
216+
case ZNOT | ZAND | ZOR => true
217+
case _ => false
218+
}
219+
220+
def isShiftOp(code: Int): Boolean = code match {
221+
case LSL | LSR | ASR => true
222+
case _ => false
223+
}
224+
225+
def isBitwiseOp(code: Int): Boolean = code match {
226+
case OR | XOR | AND => true
227+
case _ => false
228+
}
229+
230+
def isCoercion(code: Int): Boolean = (code >= B2B) && (code <= D2D)
231+
232+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package dottyBench.tools
2+
package backend
3+
4+
import scala.collection.mutable
5+
6+
/**
7+
* Simple implementation of a worklist algorithm. A processing
8+
* function is applied repeatedly to the first element in the
9+
* worklist, as long as the stack is not empty.
10+
*
11+
* The client class should mix-in this class and initialize the worklist
12+
* field and define the `processElement` method. Then call the `run` method
13+
* providing a function that initializes the worklist.
14+
*
15+
* @author Martin Odersky
16+
* @version 1.0
17+
* @see [[scala.tools.nsc.backend.icode.Linearizers]]
18+
*/
19+
trait WorklistAlgorithm {
20+
type Elem
21+
class WList {
22+
private var list: List[Elem] = Nil
23+
def isEmpty = list.isEmpty
24+
def nonEmpty = !isEmpty
25+
def push(e: Elem): Unit = { list = e :: list }
26+
def pop(): Elem = {
27+
val head = list.head
28+
list = list.tail
29+
head
30+
}
31+
def pushAll(xs: Iterable[Elem]): Unit = xs.foreach(push)
32+
def clear(): Unit = list = Nil
33+
34+
}
35+
36+
val worklist: WList
37+
38+
/**
39+
* Run the iterative algorithm until the worklist remains empty.
40+
* The initializer is run once before the loop starts and should
41+
* initialize the worklist.
42+
*/
43+
def run(initWorklist: => Unit) = {
44+
initWorklist
45+
46+
while (worklist.nonEmpty)
47+
processElement(dequeue)
48+
}
49+
50+
/**
51+
* Process the current element from the worklist.
52+
*/
53+
def processElement(e: Elem): Unit
54+
55+
/**
56+
* Remove and return the first element to be processed from the worklist.
57+
*/
58+
def dequeue: Elem
59+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package dottyBench.tools
2+
package backend
3+
package jvm
4+
5+
import scala.tools.asm.tree.{AbstractInsnNode}
6+
import java.io.PrintWriter
7+
import scala.tools.asm.util.{TraceClassVisitor, TraceMethodVisitor, Textifier}
8+
import scala.tools.asm.ClassReader
9+
10+
object AsmUtils {
11+
12+
/**
13+
* Print the bytecode of methods generated by GenBCode to the standard output. Only methods
14+
* whose name contains `traceMethodPattern` are traced.
15+
*/
16+
final val traceMethodEnabled = sys.env.contains("printBCODE")
17+
final val traceMethodPattern = sys.env.getOrElse("printBCODE", "")
18+
19+
/**
20+
* Print the bytecode of classes generated by GenBCode to the standard output.
21+
*/
22+
final val traceClassEnabled = false
23+
final val traceClassPattern = ""
24+
25+
/**
26+
* Print the bytedcode of classes as they are serialized by the ASM library. The serialization
27+
* performed by `asm.ClassWriter` can change the code generated by GenBCode. For example, it
28+
* introduces stack map frames, it computes the maximal stack sizes, and it replaces dead
29+
* code by NOPs (see also https://github.com/scala/scala/pull/3726#issuecomment-42861780).
30+
*/
31+
final val traceSerializedClassEnabled = false
32+
final val traceSerializedClassPattern = ""
33+
34+
def traceMethod(mnode: MethodNode1): Unit = {
35+
println(s"Bytecode for method ${mnode.name}")
36+
val p = new Textifier
37+
val tracer = new TraceMethodVisitor(p)
38+
mnode.accept(tracer)
39+
val w = new PrintWriter(System.out)
40+
p.print(w)
41+
w.flush()
42+
}
43+
44+
def traceClass(cnode: ClassNode1): Unit = {
45+
println(s"Bytecode for class ${cnode.name}")
46+
val w = new PrintWriter(System.out)
47+
cnode.accept(new TraceClassVisitor(w))
48+
w.flush()
49+
}
50+
51+
def traceClass(bytes: Array[Byte]): Unit = traceClass(readClass(bytes))
52+
53+
def readClass(bytes: Array[Byte]): ClassNode1 = {
54+
val node = new ClassNode1()
55+
new ClassReader(bytes).accept(node, 0)
56+
node
57+
}
58+
59+
def instructionString(instruction: AbstractInsnNode): String = instruction.getOpcode match {
60+
case -1 => instruction.toString
61+
case op => scala.tools.asm.util.Printer.OPCODES(op)
62+
}
63+
}

0 commit comments

Comments
 (0)