Cross-ISA Debugging in Meta-circular VMs VMIL17 , 24 Oct 2017 - - PowerPoint PPT Presentation

cross isa debugging in meta circular vms
SMART_READER_LITE
LIVE PREVIEW

Cross-ISA Debugging in Meta-circular VMs VMIL17 , 24 Oct 2017 - - PowerPoint PPT Presentation

Cross-ISA Debugging in Meta-circular VMs VMIL17 , 24 Oct 2017 Christos Kotselidis Andy Nisbet Foivos S. Zakkak Nikos Foutris Except where otherwise noted, this presentation is licensed under the Creative Commons Attribution-ShareAlike 4.0


slide-1
SLIDE 1

Cross-ISA Debugging in Meta-circular VMs

VMIL’17, 24 Oct 2017 Christos Kotselidis Andy Nisbet Foivos S. Zakkak Nikos Foutris

Except where otherwise noted, this presentation is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. Third party marks and brands are the property of their respective holders.

slide-2
SLIDE 2

1 Introduction 1/ 19

Meta-circular VMs

■ VMs written in the language they are meant to implement ■ Meta-circular VMs use their own compilers to build themselves

(create a boot image)

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-3
SLIDE 3

1 Introduction 2/ 19

Development challenges

Porting Meta-circular VMs to new Instruction Set Architectures

■ No existing compilers for the target ISA ■ Need to implement at least all the components required to build the boot image ■ Compiler bugs prevent the VM from starting ■ Testing of the compiler cannot be performed without the VM running ■ No suffjcient tools (e.g. testing framework) to assist in the above process

Debugging the boot image

■ Exceptions might appear before we can even print and/or trace them Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-4
SLIDE 4

1 Introduction 2/ 19

Development challenges

Porting Meta-circular VMs to new Instruction Set Architectures

■ No existing compilers for the target ISA ■ Need to implement at least all the components required to build the boot image ■ Compiler bugs prevent the VM from starting ■ Testing of the compiler cannot be performed without the VM running ■ No suffjcient tools (e.g. testing framework) to assist in the above process

Debugging the boot image

■ Exceptions might appear before we can even print and/or trace them Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-5
SLIDE 5

1 Introduction 3/ 19

Our approach

Porting Meta-circular VMs to new Instruction Set Architectures

Cross-compile unit tests and run using virtualization

Debugging the boot image

Injection of special assembly instructions acting as markers that helps us map the failing native function (even if inlined) to the corresponding VM method

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-6
SLIDE 6

2 Background 4/ 19

Maxine VM

■ Meta-circular VM ■ Originally a Sun and Oracle Labs project,

maintained by the University of Manchester since project kenai shut down https://github.com/beehive-lab/Maxine-VM

■ Ported to ARMv7 using the tools presented in this talk ■ Ongoing porting to ARMv8 using the same tools Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-7
SLIDE 7

2 Background 5/ 19

Maxine VM Outline

Maxine VM

Compilation Broker

T1X: Baseline Compiler C1X: Optimizing Compiler Graal: Optimizing Compiler

HeapScheme | GC

SemiSpaceHeapScheme GenerationalHeapScheme

Other Schemes

ReferenceScheme LayoutScheme MonitorScheme

JDK Integration Threading Native Calls | JNI

Maxine C Code | Substrate

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-8
SLIDE 8

2 Background 6/ 19

Maxine’s Compilers

T1X Template based compiler, used instead of an interpreter + Fast compilation − Minimal to no optimizations C1X Optimizing compiler (C1 ported to Java) + Optimizing − Slower Compilation Graal Optimizing compiler (Alternative or complementary to C1X) + Aggressive Optimizations − Slower Compilation − Experimental

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-9
SLIDE 9

3 QEMU-based Cross-ISA Debugging Toolchain 7/ 19

QEMU-based Cross-ISA Debugging Toolchain

■ Initialization (Create a code bufger, set expected values, etc.) ■ Code generation (fjll the bufger with the generated code) ■ Creation of an executable (assemble, compile, and link)

$ arm-unknown-eabi-gcc -c -march=armv7-a -g test_armv7.c -o test_armv7.o $ arm-unknown-eabi-as -mcpu=cortex-a9 -g startup_armv7.s -o startup_armv7.o $ arm-unknown-eabi-ld -T test_armv7.ld test_armv7.o startup_armv7.o -o test.elf $ arm-unknown-eabi-objcopy -O binary test.elf test_armv7.bin

■ Run binary using QEMU and gdb

$ qemu-system-arm -cpu cortex-a9 -M versatilepb -m 128M -nographic -s -S -kernel test_armv7.bin $ arm-none-eabi-gdb # target remote localhost:1234

■ Validate results (compare register values to expected ones) Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-10
SLIDE 10

3 QEMU-based Cross-ISA Debugging Toolchain 8/ 19

Supported Kind of tests

■ Individual Assembly Instructions ■ T1X Compiled Methods ■ C1X Compiled Methods Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-11
SLIDE 11

3 QEMU-based Cross-ISA Debugging Toolchain 9/ 19

Benefjts

■ Ease porting to new ISAs by enabling cross-ISA debugging ■ Speedup regression and enhance productivity by: □ testing cross-ISA compilers on more powerful than the target machines

(e.g. x86 vs ARMv7)

□ not building the image for unit testing

1 $ time mx image 2 132.67s user 3.60s system 421% cpu 32.365 total

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-12
SLIDE 12

4 Examples 10/ 19

Examples

Live demo at the end (if time permits)!

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-13
SLIDE 13

4 Examples 11/ 19

Unit Test for ARMv7 add Assembly Instruction

1 public void test_add() throws Exception { 2 for (int i = 0; i < 10; i++) { 3 asm.movImm32(ConditionFlag.Always, ARMV7.cpuRegisters[i], expectedValues[i]); 4 asm.addq(ARMV7.cpuRegisters[i], expectedValues[i]); 5 6 expectedValues[i] += expectedValues[i]; 7 testValues[i] = true; 8 } 9 10 generateAndTest(expectedValues , testValues , bitmasks, asm.codeBuffer); 11 }

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-14
SLIDE 14

4 Examples 12/ 19

Unit Test for ARMv7 T1X add Template

1 public void test_add() throws Exception { 2 initializeFrameForCompilation(); 3 4 t1xCompiler.do_iconst(1); 5 t1xCompiler.do_iconst(2); 6 t1xCompiler.do_iadd(); 7 8 expected[0] = 3; 9 10 generateAndTest(expectedValues); 11 }

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-15
SLIDE 15

4 Examples 13/ 19

BC_iadd2 Unit Test

1 package jtt.bytecode; 2 3 /* 4 * @Harness: java 5 * @Runs: (1b,2b)=3; (0b,-1b)=-1; (33b,67b)=100; (1b, -1b)=0; 6 * @Runs: (-128b,1b)=-127; (127b,1b)=128; 7 */ 8 public class BC_iadd2 { 9 10 public static int test(byte a, byte b) { 11 return a + b; 12 } 13 14 }

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-16
SLIDE 16

4 Examples 14/ 19

Unit Test for ARMv7 C1X Compilation

1 public void test_C1X_jtt_BC_iadd2() throws Exception { 2 byte[] argsOne = {1, 0, 33, 1, -128, 127}; 3 byte[] argsTwo = {2, -1, 67, -1, 1, 1}; 4 initTests(); 5 String klassName = getKlassName("jtt.bytecode.BC_iadd"); 6 List<TargetMethod > methods = Compiler.compile(new String[] {klassName}, "C1X"); 7 initializeCodeBuffers(methods, "BC_iadd2.java", "int test(byte, byte)"); 8 9 for (int i = 0; i < argsOne.length; i++) { 10 int expectedValue = jtt.bytecode.BC_iadd2.test(argsOne[i], argsTwo[i]); 11 String functionPrototype = 12 ARMCodeWriter.preAmble("int", "int, int ", Integer.toString(argsOne[i]) + "," + Integer.toString(argsTwo[i])); 13 Object[] registerValues = generateObjectsAndTestStubs(functionPrototype , entryPoint , codeBytes); 14 assert (Integer) registerValues[0] == expectedValue; 15 } 16 }

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-17
SLIDE 17

5 Limitations 15/ 19

Limitations

We still can’t test the following without booting the VM

■ Object allocation ■ Garbage collection ■ Synchronization ■ Inline assembly (compiler stubs, adapters from T1X to C1X, etc.)

As a result, starting the VM on the target ISA is expected to result in a number of hard faults (e.g. SIGSEGV)

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-18
SLIDE 18

6 Tracing Runtime Faults 16/ 19

Tracing Runtime Faults

■ Extend C1X and T1X to inject special assembly instructions:

  • 1. that act as markers that we can easily fjnd when going through a gdb backtrace
  • 2. holding a unique, per method, ID

■ Create a fjle, mapping the unique IDs to the corresponding Java methods ■ On failure:

  • 1. Run the VM inside gdb
  • 2. Print the backtrace
  • 3. Look for the closest marker before the failing instruction
  • 4. Obtain the method ID and look it up in the map fjle

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-19
SLIDE 19

6 Tracing Runtime Faults 17/ 19

Tracing Runtime Faults Outline

Task Graph Compiler (C1X | T1X) MethodIDLIRNode Assembler

Parse method Create foo( ) IR Graph MethodIDNode Inlined Call MethodIDNode

foo( ) assembly

movw r8, 0xdead (r8:scratch) | marker movt r8, 0xbeef | marker movw r8, id (bottom 16 bits) movt r8, id (upper 16 bits) … generated assembly of foo( )

generate c1x | t1x_method_ids.txt id offset method 1 0 foo( ) (parent) 1 12 bar( ) (inlined) 2 0 …

Method Database Add MethodIDNodes in IR

append

lower

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-20
SLIDE 20

7 Demo 18/ 19

Demo Time

Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-21
SLIDE 21

8 Conclusions 19/ 19

Conclusions

■ Enable Cross-ISA debugging ■ Speedup development □ Unit testing compilers without building the image □ Unit testing on stronger machines than the potentially weaker target ■ Improve bootstrap debugging by injecting special instructions Cross-ISA Debugging in Meta-circular VMs

  • F. Zakkak - foivos.zakkak@manchester.ac.uk
slide-22
SLIDE 22

Thank You!

Cross-ISA Debugging in Meta-circular VMs

VMIL’17, 24 Oct 2017 Christos Kotselidis Andy Nisbet Foivos S. Zakkak Nikos Foutris