-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add -runtime-code-size option to reserve a region for JIT code
- Loading branch information
Showing
9 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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
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
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,99 @@ | ||
def RUNTIME_CODE_SIZE = 4096; | ||
|
||
var result = 0; | ||
|
||
def main(args: Array<string>) -> int { | ||
begin("code size check"); | ||
checkCodeSize(); | ||
|
||
begin("generating code"); | ||
generateCode(); | ||
|
||
begin("checking code"); | ||
checkCode(); | ||
|
||
begin("running code"); | ||
runCode(); | ||
|
||
return result; | ||
} | ||
|
||
def checkCodeSize() { | ||
var gotSize = int.!(CiRuntime.RUNTIME_CODE_END - CiRuntime.RUNTIME_CODE_START); | ||
if (RUNTIME_CODE_SIZE == gotSize) ok(); | ||
else return fail("size does not match"); | ||
} | ||
|
||
def generateCode() { | ||
var region = getRuntimeCodeRegion(); | ||
var expected = getMachineCode(); | ||
for (i < expected.length) { | ||
region[i] = expected[i]; | ||
} | ||
ok(); | ||
} | ||
|
||
def checkCode() { | ||
var region = getRuntimeCodeRegion(); | ||
var expected = getMachineCode(); | ||
if (region.length == 0) return fail("no reserved code region"); | ||
if (region.length < expected.length) return fail("reserved code region too small"); | ||
for (i < expected.length) { | ||
if (region[i] != expected[i]) return fail("machine code does not match expectation"); | ||
} | ||
ok(); | ||
} | ||
|
||
def runCode() { | ||
var codePtr = CiRuntime.RUNTIME_CODE_START; | ||
var f: void -> int = CiRuntime.forgeClosure<void, void, int>(codePtr, ()); | ||
var got = f(); | ||
if (got == 42) ok(); | ||
else fail("got wrong value"); | ||
} | ||
|
||
def begin(str1: string) { | ||
System.puts("##+"); | ||
System.puts(str1); | ||
System.ln(); | ||
} | ||
|
||
def ok() { | ||
System.puts("##-ok\n"); | ||
} | ||
|
||
def fail(msg: string) { | ||
System.puts("##-fail: "); | ||
if (msg != null) System.puts(msg); | ||
System.ln(); | ||
result |= 1; | ||
} | ||
|
||
def getRuntimeCodeRegion() -> Range<byte> { | ||
return CiRuntime.forgeRange<byte>(CiRuntime.RUNTIME_CODE_START, | ||
int.!(CiRuntime.RUNTIME_CODE_END - CiRuntime.RUNTIME_CODE_START)); | ||
} | ||
|
||
//========================================================================================== | ||
//== Target-specific configuration ========================================================= | ||
//========================================================================================== | ||
|
||
// Retarget this test by passing -redef-field=TARGET_<target>=true | ||
def TARGET_x86_linux = false; | ||
def TARGET_x86_darwin = false; | ||
def TARGET_x86_64_linux = false; | ||
def TARGET_x86_64_darwin = false; | ||
|
||
def TARGET_x86 = TARGET_x86_linux || TARGET_x86_darwin; | ||
def TARGET_x86_64 = TARGET_x86_64_linux || TARGET_x86_64_darwin; | ||
|
||
def X86_CODE: Array<byte> = [ | ||
0xB8, 0x2A, 0x00, 0x00, 0x00, // mov eax, 42 | ||
0xc3 // ret | ||
]; | ||
|
||
def getMachineCode() -> Array<byte> { | ||
if (TARGET_x86 || TARGET_x86_64) return X86_CODE; | ||
var x = 1/0; | ||
return null; // no other targets supported now | ||
} |
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 @@ | ||
0 |
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 @@ | ||
foo |
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 @@ | ||
-runtime-code-size=4K |