Homework B (benchmarks)
This commit is contained in:
parent
72cc3206c4
commit
76fbabdf53
141 changed files with 7477 additions and 1969 deletions
|
|
@ -5,7 +5,7 @@
|
|||
<classpathentry kind="lib" path="lib/junit-4.12.jar"/>
|
||||
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
|
||||
<classpathentry kind="lib" path="lib/antlr-4.7.1-complete.jar"/>
|
||||
<classpathentry kind="lib" path="lib/javaliParserObf.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="lib" path="lib/javaliParserObf.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
|||
2
.project
2
.project
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Javali-HW4</name>
|
||||
<name>Javali-HWB</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
|
|
|||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
7
.settings/org.eclipse.jdt.core.prefs
Normal file
7
.settings/org.eclipse.jdt.core.prefs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
54
Grade.txt
54
Grade.txt
|
|
@ -1,39 +1,15 @@
|
|||
nop90: 29/30 points
|
||||
|
||||
Comments:
|
||||
I found that the following tasks were not implemented correctly or contained errors.
|
||||
|
||||
* Null pointers check doesn't work for methods:
|
||||
"
|
||||
class Main {
|
||||
void main() {
|
||||
A a;
|
||||
a.m();
|
||||
}
|
||||
}
|
||||
class A {
|
||||
void m() { }
|
||||
}
|
||||
"
|
||||
* Side effects
|
||||
If methods have side effects, then the execution order matters:
|
||||
"
|
||||
class Main {
|
||||
void main() {
|
||||
write(m1() + m2());
|
||||
writeln();
|
||||
}
|
||||
|
||||
int m1() {
|
||||
write(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int m2() {
|
||||
write(2);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
"
|
||||
* Can't compile programs which use many registers
|
||||
|
||||
team name: nop90
|
||||
task 1 correctness: 95
|
||||
task 1 score: 541.3
|
||||
task 1 points (max 25 points): 16
|
||||
task 2 deadline 1 correctness: 100
|
||||
task 2 deadline 1 score: 14.1
|
||||
task 2 deadline 1 points: 1
|
||||
task 2 deadline 2 correctness: 97
|
||||
task 2 deadline 2 score: 264.5
|
||||
task 2 deadline 2 points: 15
|
||||
task 2 runtimeOpts correctness: 98
|
||||
task 2 runtimeOpts score: 265.3
|
||||
task 2 runtimeOpts bonus points: 0
|
||||
task 2 points (max 25 points): 15
|
||||
HWB TOTAL (max 50 points): 31
|
||||
16
Javali tests.launch
Normal file
16
Javali tests.launch
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/Javali"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="4"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=Javali"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Javali"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcd.meta_hidden.Version=REFERENCE"/>
|
||||
</launchConfiguration>
|
||||
111
README.md
111
README.md
|
|
@ -1,111 +0,0 @@
|
|||
# HW4: code generation
|
||||
Better viewed as markdown
|
||||
|
||||
# VTables
|
||||
They are generated when each class is visited, except for those of Object,
|
||||
Object[], int[] and boolean[], which are generated in the bootstrapping.
|
||||
|
||||
When the object vtable is generated, so is the array table, which just
|
||||
contains a reference to the supertype (in our case `Object`) and an unused
|
||||
pointer to the declared type of the element's vtable.
|
||||
|
||||
supertype pointer (Object) <-- vtable pointer
|
||||
element vtable pointer (unused)
|
||||
|
||||
Each type's vtable contains the supertype as the first element (trait shared
|
||||
with array type's vtables for easier cast type comparisons). Then they
|
||||
contain all the methods available to an object of that type, including
|
||||
all those inherited. As the dynamic type is not known, the number and
|
||||
position of the methods is not known when executing a method, therefore
|
||||
each method's pointer is prepended by the method's name hash (similar to
|
||||
fields in an object).
|
||||
|
||||
supertype pointer <-- vtable pointer
|
||||
hash("method0")
|
||||
method0 pointer
|
||||
hash("method1")
|
||||
method1 pointer
|
||||
...
|
||||
hash("methodN")
|
||||
methodN pointer
|
||||
|
||||
# Method calls
|
||||
|
||||
The basic scheme used for method calls and the structure of the stack
|
||||
frame is that described in the `__cdecl` used in GCC. In short, this is
|
||||
the execution of a method call:
|
||||
|
||||
1. The caller pushes the arguments in the stack, from right-to-left,
|
||||
leaving the 0th argument (the reference to `this`) at the top of the stack.
|
||||
2. The caller executes `call` (the instruction pointer gets stored in the stack)
|
||||
3. The callee now takes control, and its first action is to save the base
|
||||
pointer to the stack and set the base pointer to the current stack pointer.
|
||||
Therefore, the arguments and return address are available to the method.
|
||||
4. The local variables are reserved and zeroed in the stack.
|
||||
5. The CALLEE_SAVED registers are saved to the stack.
|
||||
6. The method executes its code
|
||||
7. The CALLEE_SAVED registers are restored to their original status.
|
||||
8. The callee restores the stack and base registers to its initial statuses.
|
||||
This is accomplished with a `leave` instruction. Then it returns using `ret`.
|
||||
This removes the instruction pointer from the stack leaving only the arguments.
|
||||
9. The caller finally removes all the arguments from the stack and obtains the
|
||||
return value from EAX.
|
||||
|
||||
Therefore, the stack frame follows the following structure (N arguments
|
||||
and M local variables):
|
||||
|
||||
top of stack <-- ESP
|
||||
...
|
||||
saved registers
|
||||
localM <-- EBP - 4 - M * 4
|
||||
...
|
||||
local1 <-- EBP - 8
|
||||
local0 <-- EBP - 4
|
||||
Old EBP <-- EBP
|
||||
Return EIP
|
||||
this <-- EBP + 8
|
||||
arg0 <-- EBP + 12
|
||||
...
|
||||
argN <-- EBP + 12 + N * 4
|
||||
|
||||
# Variable and object representation
|
||||
## Primitive variables
|
||||
They are represented by value, with both integers and booleans occupying
|
||||
4 bytes, and booleans being represented as TRUE = 0, FALSE = 1.
|
||||
|
||||
## Reference variables
|
||||
Stored in the heap, using calloc (to zero-initialize them).
|
||||
|
||||
### Arrays
|
||||
On top of storing the array elements, some overhead is stored with it,
|
||||
namely a pointer to the array vtable for casts, and the size of the
|
||||
array to check the bounds of the array on accesses or assignments.
|
||||
The pointer to the array points to the vtable pointer (the first
|
||||
element in the object structure):
|
||||
|
||||
array vtable pointer <-- var pointer
|
||||
array size
|
||||
element0
|
||||
element1
|
||||
...
|
||||
elementN
|
||||
|
||||
### Objects
|
||||
|
||||
Stores a pointer to the object's type vtable and all the fields. As the
|
||||
dynamic type of the object cannot be determined and therefore the fields
|
||||
not statically ordered, each field occupies 8 bytes, with the first 4 containing
|
||||
the hash for the VariableSymbol that represents it and the others the
|
||||
value or reference to the field.
|
||||
|
||||
The hash allows hiding variables, but introduces an overhead when accessing
|
||||
a field, to look for the position in which it is located.
|
||||
|
||||
vtable pointer <-- var pointer
|
||||
field0's hash
|
||||
field0
|
||||
field1's hash
|
||||
field1
|
||||
...
|
||||
fieldN's hash
|
||||
fieldN
|
||||
60
benchmarks/HWB/Quicksort.javali
Normal file
60
benchmarks/HWB/Quicksort.javali
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// Overall test of arrays, loops, etc. that does a simple quicksort.
|
||||
class Record {
|
||||
int a ;
|
||||
}
|
||||
|
||||
class Main {
|
||||
Record [] a;
|
||||
int i;
|
||||
|
||||
void swap(Record r1, Record r2) {
|
||||
int temp;
|
||||
temp = 0+1;
|
||||
temp = r1.a;
|
||||
r1.a = r2.a;
|
||||
r2.a = temp;
|
||||
}
|
||||
|
||||
void sort(int left, int right) {
|
||||
int i,j;
|
||||
int m;
|
||||
|
||||
m = (a[left].a + a[right].a) / (1 + 1);
|
||||
i = left;
|
||||
j = right;
|
||||
while (i <= j) {
|
||||
while (a[i].a < m) { i = i+1; }
|
||||
while (a[j].a > m) { j = j-1; }
|
||||
if (i <= j) {
|
||||
swap(a[i], a[j]);
|
||||
i = i+1;
|
||||
j = j-1;
|
||||
}
|
||||
}
|
||||
if (left < j) { sort(left,j); }
|
||||
if (i < right) { sort(i,right); }
|
||||
}
|
||||
|
||||
void main() {
|
||||
int SIZE;
|
||||
int j;
|
||||
|
||||
SIZE = 10;
|
||||
|
||||
a = new Record[SIZE * 1];
|
||||
j = 0;
|
||||
while (j < SIZE) {
|
||||
a[j] = new Record();
|
||||
a[j].a = read();
|
||||
j = j + 1;
|
||||
}
|
||||
sort(0, SIZE-1);
|
||||
j = 0;
|
||||
while (j < SIZE) {
|
||||
i = a[j].a;
|
||||
write(i);
|
||||
writeln();
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
benchmarks/HWB/Quicksort.javali.in
Normal file
10
benchmarks/HWB/Quicksort.javali.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
1
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
5
|
||||
2
|
||||
4
|
||||
6
|
||||
3
|
||||
40
benchmarks/HWB_nop90/AFewConstants.javali
Normal file
40
benchmarks/HWB_nop90/AFewConstants.javali
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
class Main {
|
||||
int SIZE;
|
||||
|
||||
void main() {
|
||||
int[] a;
|
||||
int i;
|
||||
int pi;
|
||||
int e;
|
||||
int thou;
|
||||
|
||||
pi = 3141;
|
||||
e = 2718;
|
||||
|
||||
a = readStuff();
|
||||
|
||||
i = 0;
|
||||
while(i < SIZE) {
|
||||
write(pi * e * a[i] / (1000 * 1000));
|
||||
writeln();
|
||||
write(a[i] * pi * e / (1000 * 1000));
|
||||
writeln();
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int[] readStuff() {
|
||||
int[] a;
|
||||
int i;
|
||||
|
||||
SIZE = 5;
|
||||
a = new int[SIZE];
|
||||
|
||||
i = 0;
|
||||
while (i < SIZE) {
|
||||
a[i] = read();
|
||||
i = i + 1;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
5
benchmarks/HWB_nop90/AFewConstants.javali.in
Normal file
5
benchmarks/HWB_nop90/AFewConstants.javali.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
42
|
||||
1337
|
||||
9000
|
||||
12345678
|
||||
777
|
||||
13
benchmarks/HWB_nop90/Unused.javali
Normal file
13
benchmarks/HWB_nop90/Unused.javali
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class Main {
|
||||
void main() {
|
||||
int i;
|
||||
int j;
|
||||
i = read();
|
||||
j = 2 * i;
|
||||
|
||||
i = (i + 31) / 2;
|
||||
j = (i * j) / 3;
|
||||
|
||||
write(i);
|
||||
}
|
||||
}
|
||||
1
benchmarks/HWB_nop90/Unused.javali.in
Normal file
1
benchmarks/HWB_nop90/Unused.javali.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
43
|
||||
94
build.xml
94
build.xml
|
|
@ -8,33 +8,40 @@
|
|||
<property name="src.dir" value="${basedir}/src"/>
|
||||
<property name="test.dir" value="${basedir}/test"/>
|
||||
<property name="javali_tests.dir" value="${basedir}/javali_tests"/>
|
||||
<property name="benchmarks.dir" value="${basedir}/benchmarks"/>
|
||||
<property name="parser.dir" value="${src.dir}/cd/frontend/parser"/>
|
||||
<property name="parser.jar" value="${basedir}/lib/javaliParserObf.jar"/>
|
||||
<property name="build.dir" value="${basedir}/bin"/>
|
||||
<property name="junit.jar" value="${basedir}/lib/junit-4.12.jar"/>
|
||||
<property name="hamcrest.jar" value="${basedir}/lib/hamcrest-core-1.3.jar"/>
|
||||
<property name="antlr.jar" value="${basedir}/lib/antlr-4.4-complete.jar"/>
|
||||
<property name="antlr.jar" value="${basedir}/lib/antlr-4.7.1-complete.jar"/>
|
||||
<property name="antlr.profile" value="false"/>
|
||||
<property name="antlr.report" value="false"/>
|
||||
<property name="jacocoant.jar" value="${basedir}/lib/jacocoant.jar"/>
|
||||
<property name="coverage.file" location="${build.dir}/jacoco.exec"/>
|
||||
<property name="min.coverage" value="0.5"/>
|
||||
<property name="coverage.check" value="cd.frontend.*:cd.backend.*"/>
|
||||
|
||||
<!-- Cleans generated code, but NOT the parser source! -->
|
||||
<target name="clean">
|
||||
<delete dir="${build.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile">
|
||||
<mkdir dir="${build.dir}"/>
|
||||
<!-- Builds the compiler framework for HW > HW1. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${build.dir}"/>
|
||||
|
||||
<javac debug="true" destdir="${build.dir}" includeantruntime="false">
|
||||
<src path="${src.dir}"/>
|
||||
<src path="${test.dir}"/>
|
||||
<classpath>
|
||||
<pathelement location="${antlr.jar}"/>
|
||||
<pathelement location="${junit.jar}"/>
|
||||
<pathelement location="${hamcrest.jar}"/>
|
||||
<pathelement location="${parser.jar}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
<javac debug="true" destdir="${build.dir}" includeantruntime="false">
|
||||
<src path="${src.dir}"/>
|
||||
<src path="${test.dir}"/>
|
||||
<classpath>
|
||||
<pathelement location="${antlr.jar}"/>
|
||||
<pathelement location="${junit.jar}"/>
|
||||
<pathelement location="${hamcrest.jar}"/>
|
||||
<pathelement location="${parser.jar}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!-- Deletes all byproducts of running the tests -->
|
||||
<target name="clean-test">
|
||||
|
|
@ -44,28 +51,53 @@
|
|||
<fileset dir="${javali_tests.dir}" includes="**/*.bin"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.dot"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.exe"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.ref"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.ref"/>
|
||||
|
||||
<fileset dir="${benchmarks.dir}" includes="**/*.err"/>
|
||||
<fileset dir="${benchmarks.dir}" includes="**/*.s"/>
|
||||
<fileset dir="${benchmarks.dir}" includes="**/*.bin"/>
|
||||
<fileset dir="${benchmarks.dir}" includes="**/*.dot"/>
|
||||
<fileset dir="${benchmarks.dir}" includes="**/*.exe"/>
|
||||
<fileset dir="${benchmarks.dir}" includes="**/*.ref"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
|
||||
<classpath path="${jacocoant.jar}"/>
|
||||
</taskdef>
|
||||
|
||||
<!-- Runs the tests. Use the compile target first! -->
|
||||
<target name="test" depends="compile">
|
||||
<junit fork="true" forkmode="once" failureproperty="tests-failed" outputtoformatters="false">
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<batchtest skipNonTests="true">
|
||||
<fileset dir="bin" includes="**/*.class" />
|
||||
</batchtest>
|
||||
<assertions enablesystemassertions="true" />
|
||||
<sysproperty key="cd.meta_hidden.Version" value="REFERENCE" />
|
||||
<classpath>
|
||||
<pathelement location="${build.dir}"/>
|
||||
<pathelement location="${junit.jar}"/>
|
||||
<pathelement location="${hamcrest.jar}"/>
|
||||
<pathelement location="${antlr.jar}"/>
|
||||
<pathelement location="${parser.jar}"/>
|
||||
</classpath>
|
||||
</junit>
|
||||
<fail if="tests-failed" />
|
||||
<jacoco:coverage destfile="${coverage.file}">
|
||||
<junit fork="true" forkmode="once" failureproperty="tests-failed" outputtoformatters="false">
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<batchtest skipNonTests="true">
|
||||
<fileset dir="bin" includes="**/*.class" />
|
||||
</batchtest>
|
||||
<assertions enablesystemassertions="true" />
|
||||
<sysproperty key="cd.meta_hidden.Version" value="BENCH" />
|
||||
<classpath>
|
||||
<pathelement location="${build.dir}"/>
|
||||
<pathelement location="${junit.jar}"/>
|
||||
<pathelement location="${hamcrest.jar}"/>
|
||||
<pathelement location="${antlr.jar}"/>
|
||||
<pathelement location="${parser.jar}"/>
|
||||
</classpath>
|
||||
</junit>
|
||||
</jacoco:coverage>
|
||||
<fail if="tests-failed" />
|
||||
</target>
|
||||
|
||||
<target name="bench" depends="compile">
|
||||
<java classname="cd.BenchmarksRunner" fork="yes" error="bench-log.txt">
|
||||
<classpath>
|
||||
<pathelement location="${build.dir}"/>
|
||||
<pathelement location="${antlr.jar}"/>
|
||||
<pathelement location="${junit.jar}"/>
|
||||
<pathelement location="${hamcrest.jar}"/>
|
||||
<pathelement location="${parser.jar}"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
0
javali_tests/HW1_nop90/Division.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/Division.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/EightVariablesWrite.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/EightVariablesWrite.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/Multiplication.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/Multiplication.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/Overflow.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/Overflow.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/Overflow.javali.in
Executable file → Normal file
0
javali_tests/HW1_nop90/Overflow.javali.in
Executable file → Normal file
0
javali_tests/HW1_nop90/ReadWrite.javali
Executable file → Normal file
0
javali_tests/HW1_nop90/ReadWrite.javali
Executable file → Normal file
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue