310 likes | 489 Views
OSUIF: A Closer Look. Holger Kienle UCSB http://www.cs.ucsb.edu/~osuif. OSUIF: The Basic Idea. thin layer on top of SUIF for OO languages -> extension of SUIF IR nodes lowering OSUIF -> SUIF set of basic passes client (e.g., C++/Java front end/extension) has to extend OSUIF skeleton.
E N D
OSUIF: A Closer Look Holger KienleUCSBhttp://www.cs.ucsb.edu/~osuif
OSUIF: The Basic Idea • thin layer on top of SUIF for OO languages -> extension of SUIF IR nodes • lowering OSUIF -> SUIF • set of basic passes • client (e.g., C++/Java front end/extension) has to extend OSUIF skeleton
Language Independence • three extension points for language-specific functionality: • front-end(e.g., subclass ClassSymbolTable for lookup) • lowering passes(e.g., dispatch table construction) • IR(language-specific nodes)
Language Independence (cont.) • design goal:put only language-independent parts in OSUIF; rest in front end / lowering • example:OSUIF has inheritance links but leaves semantics to be implemented by front end (abstract lookup() method)
OSUIF IR Extensions (1) new constructs: • classes and inheritance • methods and fields (static and instance) • method calls(dispatching and non-dispatching) • (exception-handling)
OSUIF IR Extensions (2) DataType GroupType StructType ClassType SingleInheritanceClassType • encapsulates methods and fields • symbol table interface
OSUIF IR Extensions (3) SuifObject AnnotableObject InheritanceLink • models relationships between classes • first-class entity
OSUIF IR Extensions (4) ProcedureSymbol VariableSymbol InstanceMethodSymbol FieldSymbol StaticMethodSymbolInstanceFieldSymbol StaticFieldSymbol • reference to owning class • LString attributes(e.g., to model access modifiers)
OSUIF IR Extensions (5) Statement CallStatement InstanceMethodCallStatement StaticMethodCallStatement • static and instance methods(this-ref vs. no this-ref) • dispatching vs. non-dispatching calls
InstanceMethodCallStatement concrete InstanceMethodSymbol : ProcedureSymbol { ClassType * reference owning_class omitted; bool is_dispatched default {true}; ... }; concrete InstanceMethodCallStatement : CallStatement { InstanceMethodSymbol * reference target_method; bool is_dispatched default {true}; }; • single receiver (i.e., no multiple dispatch) • dispatching and non-dispatching call
Lowering (and “Raising”) • symbols • moved in higher symbol table(reversible) • name mangling • InstanceMethodCallStatement • dispatching code • toggle is_dispatched flag and set callee_address Note: OSUIF classes are not replaced by SUIF classes!
Lowering Passes (1) • lower_osuif_symbols-lower-instance-methods-lower-static-fields-lower-static-methods-lower-per-class-symbol-table-symtab external|file_set|file_block|one-up-mangle-name <how>-ignore-lowering-name-annote • lower_static_method_call_expressions
Lowering Passes (2) • layout_single_inheritance_instance_fields-mangle-name <how>-ignore-lowering-name-annote • build_single_inheritance_vtbl-construct-vtbls-attach-vtbl-slot-number-annotes-ignore-no-vtbl-annote
OSUIF passes • use "as is" (default behavior)-> command line switches • front-end controls behavior of pass with SUIF annotations • customize pass via C++ subclassing
OSUIF front-ends • Java (j2s) • alpha-version • several bigger applications compile • C++ • back-end reasonably stable • front-end does not implement completelanguage yet • lowering to SUIF in place
j2s Goals • full Java support for off-line compilation • provide a good platform forOO/Java-related compiler research
j2s Caveats • compiles class files • has its own runtime system (SPARC only!) • JNI • reflection • class initialization • ... • requires Java 1.2beta2
j2s Caveats (cont'd) restrictions: • exception-handling • threads and synchronization • dynamic loading of classes • accurate GC • floating-point computations
j2s Environment Java .class file j2s OSUIF Transformations (OSUIF and j2s) OSUIF OSUIF Lowering SUIF SUIF Compiler System
j2s Compilation Helloworld.class j2s-fe j2s-glue j2s-main HelloWorld.osuif o2s HelloWorld.suif HelloWorld_glue.suif HelloWorld_main.suif s2c s2c s2c HelloWorld_main.c HelloWorld.c HelloWorld_glue.c
j2s Compilation: Link-Step (~360 classes) HelloWorld'stransitive closure: java_math_BigInteger.o ... HelloWorld.o libc.so java_lang_String.o ld hw libj2s_runtime.so HelloWorld_glue.o libjvm.so libjava.so ... HelloWorld_main.o
j2s OSUIF extensions ClassType SingleInheritanceClassType JavaAbstractClassType JavaClass JavaInterface JavaArray • distinguished Java constructs • tiny layer on top of OSUIF
j2s Status • generates C code (s2c) • running applications: • javac (538 classes) • SPECjvm98 benchmarks: • _201_compress • _202_db • _202_jess
How to get started... • "The j2s User Manual" • restrictions • modified class files • setup • $J2SHOME and $PATH • $JAVAHOME and $JVMCLASSPATH • $LD_LIBRARY_PATH
How to get started... (2) • compilation process (jmake)>jmake Helloworldbuilds Makefile.deps (dependencies) • user-customized MakefileTARGETNAME = hwCCFLAGS = -o2...include $J2SHOME/Makefile.driver.confinclude Makefile.deps
HelloWorld.java public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world!"); } }
hw Stats loop% size ./hw text data bss dec hex filename 3033666 436664 196 3470526 34f4be ./hw
hw Libs loop% ldd ./hw libthread.so.1 => /usr/lib/libthread.so.1 libj2s_runtime.so => ...prj/suif2b/j2s/solib/libj2s_runtime.so libjvm.so => /fs/oo1/local/src/jdk1.2/lib/sparc/green_threads/libjvm.so libjava.so => /fs/oo1/local/src/jdk1.2/lib/sparc/libjava.so libdl.so.1 => /usr/lib/libdl.so.1 libnet.so => /fs/oo1/local/src/jdk1.2/lib/sparc/libnet.so libzip.so => /fs/oo1/local/src/jdk1.2/lib/sparc/libzip.so libmath.so => /fs/oo1/local/src/jdk1.2/lib/sparc/libmath.so libc.so.1 => /usr/lib/libc.so.1 libw.so.1 => /usr/lib/libw.so.1 libm.so.1 => /usr/lib/libm.so.1 libsocket.so.1 => /usr/lib/libsocket.so.1 libnsl.so.1 => /usr/lib/libnsl.so.1 libmp.so.2 => /usr/lib/libmp.so.2 /usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1
hw Run (finally ;-)) loop% ./hw RTS: <clinit> executed: java/lang/System RTS: <clinit> executed: java/util/Properties RTS: <clinit> executed: java/io/FileInputStream RTS: <clinit> executed: java/io/FileDescriptor RTS: <clinit> executed: java/io/FileOutputStream ... RTS: <clinit> executed: java/lang/Integer RTS: <clinit> executed: java/lang/ref/CachedReference RTS: <clinit> executed: java/lang/Runtime RTS: <clinit> executed: java/io/BufferedWriter Hello world!
hw Run (Stats) rt_type_test_cnt: 746 checkcast_cnt: 0 rt_checkcast_class_cnt: 0 rt_checkcast_iface_cnt: 0 rt_checkcast_array_cnt: 0 instanceof_cnt: 14 rt_instanceof_class_cnt: 14 rt_instanceof_iface_cnt: 0 rt_instanceof_array_cnt: 0 rt_aastore_cnt: 732 ci_check_cnt: 1408 rt_init_class_cnt: 1382 Constructor_newInstance: 0 Class_newInstance_cnt: 2 Class_forName_cnt: 2 Method_invoke_cnt: 0 GetStaticMethodID_cnt: 0 GetMethodID_cnt: 0 GetStaticFieldID_cnt: 0 GetFieldID_cnt: 0 Field_set_static_cnt: 0 Field_get_static_cnt: 0 static_field_acc_rts_cn: 8 ci_check_succeeded_cnt: 14 rt_new_cnt: 519 rt_new_array_cnt: 161 obj_alloc_cnt: 680Class_bcNew_cnt: 3371 rt_intf_lookup_cnt: 0
Resourceshttp://www.cs.ucsb.edu/~osuif • The j2s User Manual • IL docu(osuif, osuifextension, j2s) • A SUIF Java Compiler, UCSB, TRCS98-18(inner workings of j2s; partly outdated) • Runtime Support for a Static Java Compiler,Master's Thesis by Andy Rutz