View
215
Download
0
Tags:
Embed Size (px)
Citation preview
1
OSUIF: A Closer LookHolger Kienle
UCSBhttp://www.cs.ucsb.edu/~osuif
2
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
3
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)
4
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)
5
OSUIF IR Extensions (1)
new constructs:
• classes and inheritance
• methods and fields (static and instance)
• method calls(dispatching and non-dispatching)
• (exception-handling)
6
OSUIF IR Extensions (2)
DataTypeGroupType
StructTypeClassType
SingleInheritanceClassType
• encapsulates methods and fields
• symbol table interface
7
OSUIF IR Extensions (3)
SuifObjectAnnotableObject
InheritanceLink
• models relationships between classes
• first-class entity
8
OSUIF IR Extensions (4)
ProcedureSymbol VariableSymbol
InstanceMethodSymbol FieldSymbol
StaticMethodSymbol InstanceFieldSymbol
StaticFieldSymbol
• reference to owning class
• LString attributes(e.g., to model access modifiers)
9
OSUIF IR Extensions (5)
StatementCallStatement
InstanceMethodCallStatementStaticMethodCallStatement
• static and instance methods(this-ref vs. no this-ref)
• dispatching vs. non-dispatching calls
10
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
11
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 bySUIF classes!
12
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
13
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
14
OSUIF passes
• use "as is" (default behavior)-> command line switches
• front-end controls behavior of pass with SUIF annotations
• customize pass via C++ subclassing
15
OSUIF front-ends
• Java (j2s)– alpha-version– several bigger applications compile
• C++– back-end reasonably stable– front-end does not implement complete
language yet– lowering to SUIF in place
16
j2s Goals
• full Java support for off-line compilation
• provide a good platform forOO/Java-related compiler research
17
j2s Caveats
• compiles class files
• has its own runtime system (SPARC only!)– JNI– reflection– class initialization– ...
• requires Java 1.2beta2
18
j2s Caveats (cont'd)
restrictions:
• exception-handling
• threads and synchronization
• dynamic loading of classes
• accurate GC
• floating-point computations
19
j2s EnvironmentJava .class file
j2s
OSUIF
OSUIF Lowering
OSUIFTransformations
(OSUIF and j2s)
SUIF
SUIFCompiler System
20
j2s Compilation
Helloworld.class
HelloWorld.osuif
HelloWorld.suif
HelloWorld.c
HelloWorld_glue.suif HelloWorld_main.suif
HelloWorld_glue.c HelloWorld_main.c
j2s-fej2s-glue j2s-main
o2s
s2c s2cs2c
21
j2s Compilation: Link-Step
HelloWorld'stransitive closure:
HelloWorld.o
java_lang_String.o
java_math_BigInteger.o
...
(~360 classes)
ldlibj2s_runtime.so
HelloWorld_glue.o
HelloWorld_main.o
libjvm.solibjava.so...
libc.so
hw
22
j2s OSUIF extensions
ClassTypeSingleInheritanceClassType
JavaAbstractClassTypeJavaClassJavaInterfaceJavaArray
• distinguished Java constructs
• tiny layer on top of OSUIF
23
j2s Status
• generates C code (s2c)
• running applications:– javac (538 classes)– SPECjvm98 benchmarks:
•_201_compress•_202_db•_202_jess
24
How to get started...
• "The j2s User Manual"– restrictions– modified class files– setup
•$J2SHOME and $PATH•$JAVAHOME and $JVMCLASSPATH•$LD_LIBRARY_PATH
25
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
26
HelloWorld.java
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
27
hw Stats
loop% size ./hw
text data bss dec hex filename
3033666 436664 196 3470526 34f4be ./hw
28
hw Libsloop% 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
29
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!
30
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: 680 Class_bcNew_cnt: 3371
rt_intf_lookup_cnt: 0
31
Resources http://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