12.07.2015 Views

phoneME Feature VM - download - Java

phoneME Feature VM - download - Java

phoneME Feature VM - download - Java

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Non-blocking and Hybrid Scheduling• Blocking OS calls need special handling• Non-blocking scheduling (preferred)> Platform requirement: for every blocking call there is a nonblockingcounterpart> SNI interface: src/vm/share/native/sni.h• Hybrid scheduling> Platform requirement: several OS threads are available, blockingcalls are reentrant> ANI interface: src/anilib/share/ani.h6


Wallll--Mounttiing OpttiionPart of the packaging is a wall-mounting template. If you want to mount themodem on a wall, cut the template out and use it as follows (see figure 1).1. Use template to mark positions of holes as indicated in table A.Table A.If you mount themodem on...Left side of cornerRight side of cornerArea of wall away fromcornerMark positions of holesA1 and A2B1 and B2Either A1 and A2 or B1and B22. Drill the marked holes with a 6-mm (0.24-in.) diameter drill bit to a minimumdepth of 35 mm (1.38 in.).3. Insert the wall plugs in the drilled holes.4. Insert the screws in the wall plugs and tighten them, leaving at least 3 mm(0.12 in.) protruding.5. Position the modem over the upper screw (A1 or B1) and pull the box downuntil you hear a click.6. Rotate the modem toward the lower screw (A2 or B2) and push it until youhear a click.


Dynamic Adaptive Compiler• Single-pass, no intermediate representation• Driven by dynamic profiler• Can be temporarily disabled> To speed up application startup> When memory is scarce> To speed up application startup– Avoid compiling during program phase transitions• Schedulable to avoid pauses> long compilations– When MaxCompilationTime is exceeded, compiler is suspended> clustering of the pauses– Compilation is not started or resumed until application isactive at least for CompilationAbstinenceTiсks9


Dynamic Profiling• Combines sampling and code instrumentation• Sampling> On profiler timer tick, scan one or a few top frames of currentthread> Inexpensive> Imprecise: can miss call-intensive short methods• Code instrumentation> Precise> Expensive for short loops• Solution: to instrument calls, to sample loops> On a method call, the method is recorded into cyclicinterpretation log> On a timer tick, scan interpretation log and a few top frames10


Dynamic Adaptive Compiler Tracing• Tracing> PrintCompilation> PrintCompiledCode> PrintCompiledCodeAsYouGo> GenerateCompilerComments> CompileOnlyClass> CompileOnlyMethod> TraceFailedCompilation> TraceMethodInlining12


<strong>Java</strong> Heap LayoutMonet Image (S<strong>VM</strong> only)_preallocated_space_glue_codeCompiler glue code_heap_startOld generationYoung generation (allocated)Young generation (free)Unused space (if any)Compiled code cacheTemporary data of compilerLarge object area (M<strong>VM</strong> only)Immovable Marking native stack user objects_young_generation_start_inline_allocation_top_inline_allocation_end_compiler_area_start_compiler_area_top_large_object_area_bottom_heap_top_heap_end13


Object header• Single word• Represents:> Object class> Hash value> Synchronisation lock> Forwarding pointer (during GC)• Array header> Extra word for array length14


Garbage Collector• Generational mark-and-compact collector> Memory is scarce, heap occupancy is high• Phases of garbage collection> Mark reachable objects> Compute new object locations> Relocate object pointers> Move objects to the new location• Remembered set> Represented as a bitvector, one bit per aligned word> Write barrier sets a bit when a pointer to young object isstored in a field of old object, minor GC scans the bitvector> The same bitvector is used for object marking15


Garbage Collector• Fast sequential “pointer-bumping" allocation• Preserves allocation order of objects> Better data cache locality> Used in forwarding pointer compression and memory quotamanagement• Sliding young generation> Size and movement are controlled to balance duration andperformance of minor collections• “En masse” promotion policy> If after minor collection percentage of survived objects isbelow YoungGenerationSurvivalTargetPercentage, retain allsurvivors in young generation. Otherwise promote all ofthem to old generation.16


Generational CollectionOld generationYoung generationAllocatedFreeEmptyFast allocations, no collections until out of memoryAllocatedEmptyMinor GC – young generation is collectedSurvivedFreeEmptyIf necessary, promote the survivors, move young generationFreeEmptyIf not enough memory freed, proceed with full collectionFreeEmpty17


Adaptive Heap Resizing• Heap size> Automatic: HeapCapacity, MinHeapSize> Or manual: set_heap_limit() (optional)• Young generation size> Controlled by YoungGenerationTarget> Default value is close to the optimal for most applications> Do not tweak unless really necessary18


Garbage Collector• Tracing of collections> TraceGC - very verbose> VerboseGC> TraceHeapSize – heap size changes• Source code:> src/vm/share/memory/ObjectHeap.cpp19


Compiled Code Cache• Dynamic profiler tracks the working set> Hot bytecode methods are compiled and stored in the cache> Cold compiled methods are evicted from the cache• Code cache size is dynamically adjusted> Controlled by CompilerAreaPercentage> Shrinks to zero on memory overflow• Tracing> TraceCompiledMethodCache (very verbose)> TraceCompilerGC• Source code:> src/vm/share/memory/CompiledMethodCache.cpp> CodeGenerator::method_prolog()20


Multitasking within a single process(M<strong>VM</strong>)• Reduced Isolates API (JSR 121)> Extended with memory quotas> src/javaapi/share/com/sun/cldc/isolate• Each <strong>Java</strong> task (isolate) represents an instance of J<strong>VM</strong>• The isolates share> Runtime> Class metadata> Object heap• Mutable state of an application is isolated in its isolate• Internally Isolates are represented by Tasks> src/vm/share/runtime/Task.cpp21


Resource Management in M<strong>VM</strong>• <strong>VM</strong> manages CPU and memory in the heap> Fare token-based thread scheduling with task and threadpriorities> Non-linear scales supported– To ensure smooth execution of the foreground task– TaskPriorityScale• AMS has to multiplex and manage all other resources> Files and sockets> Input and output22


Memory Quotas• Quota is a pair of Limit and Reservation> Default limit is max_int> Default reservation is zero• Limit guarantees that the task will never allocate morethan the specified amount of memory• Reservation guarantees that the task will always haveat least the specified amount of memory> A task with high reservation may fail to start• Free memory in excess of task reservations is shared• Exact & synchronous quota management> OutOfMemory exception is thrown exactly at the moment ofviolation23


ROMizer• Stand-alone utility a.k.a. Class Prelinker or ClassPreloader> Loads, verifies, optimizes and converts system classes toROMImage.cpp to compile and link with J<strong>VM</strong>> Special <strong>VM</strong> build> Configuration file src/vm/cldc_rom.cfg> Faster startup, smaller footprint, better performance• Source code:> src/vm/share/ROM/ROMWriter.cpp> src/vm/share/ROM/SourceROMWriter.cpp> src/vm/share/ROM/SourceObjectWriter.cpp24


Optimizations for Size• CompactROMFieldTables> Discard fields inaccessible for applications• RenameNonPublicROMClasses> Don't forget to exclude classes accessed via Class.forName or KNI• RenameNonPublicROMSymbols (fields, methods)> Don't forget to exclude fields accessed via KNI• AggressiveROMSymbolRenaming> Including public members of non-public classes• RewriteROMConstantPool> Merge constant pools of ROMized classes25


Optimizations for Speed• MakeRestrictedPackagesFinal and HiddenPackage> Helps AOT and DAC compilers to generate better code• SimpleROMInliner> Inline small methods (fields accessors and constructors)• GenerateROMStructs> Generate ROMStructs.h for direct access of native code to the fields of objectsof ROMized classes• InitAtBuild = class-name> Initialize the given class at build time, remove the initializer> Especially useful for initialization of large arrays> Must be used with caution> +ENABLE_PREINITED_TASK_MIRRORS for M<strong>VM</strong>• DontCompile = pattern26


Ahead-of-Time Compilation ofROMized methods• Precompile = pattern> Compile the matching method(s)> ROMize the compiled code> Compiled code is not writeable, so code modification andspeculative optimizations are not applicable• Speeds-up J<strong>VM</strong> startup• Reduces RAM usage• Increases ROM footprint> ≈6-8x for ARM> If ROM footprint is an issue, profile first, then select hot methods27


ROMizer Logging and Tracing• Detailed romization log> dist/lib/ROMLog.txt> Size of ROM image blocks (TEXT, DATA, HEAP)> Statistics by object types (what goes where)> Global flag values and build options> Summary for all performed optimizations• Tracing> TraceRomizer> GenerateROMComments> VerboseROMComments28


Monet• Built-in <strong>VM</strong> feature to convert of an application or alibrary to a binary image which can be mapped tomemory and executed> Must be enabled at <strong>VM</strong> build-time ENABLE_MONET=true• Greatly decreases application startup time• At conversion time, selective ahead-of-timecompilation can be performed• ... and selected static initializers can be executed too.• Application image can be:> Stored in ROM at the time of device manufacturing> Saved by AMS in secure file system at application install time• Supports multiple and shared images (LIBlets)29


Shared Monet Images Use CaseTask 1SystemMIDlet AROMizedsystem classesTask 2JSR XMIDlet BJSR Y Task 3MIDlet C30


Monet APIs• Command-line options -convert, -convertshared> Convert: cldc_vm -cp classpath -convert app.jar -romoutputfile app.bun> Run: cldc_vm -cp app.bun;app.jar main_app_class• Native interface:> jint J<strong>VM</strong>_CreateAppImage(const JvmPathChar *jarFile,> const JvmPathChar *binFile, int flags);• <strong>Java</strong> interface (M<strong>VM</strong> only):> Background conversion: other isolates are not blocked while thebinary image is created> com.sun.cldchi.jvm.J<strong>VM</strong>.createAppImage(String jarFile, String binFile,> int flags) throws Error• Flags:> REMOVE_CLASSES_FROM_JAR> GENERATE_SHARED_IMAGE31


Monet Example (in <strong>Java</strong>)final class AppImageWriter {public static void main(String[] args) {int flags = Integer.parseInt(args[2]);J<strong>VM</strong>.createAppImage(args[0], args[1], flags);}}Isolate conv = new Isolate("AppImageWriter",new String[] {“app.jar”, “/secure/app.bun”,String.valueOf(REMOVE_CLASSES_FROM_JAR)},new String[0]);conv.start();conv.waitForExit();Isolate task = new Isolate(“AppMainClass”, new String[0],new String [] {“/secure/app.bun”, “app.jar”});task.start();32


Monet• In absence of memory-mapping OS capabilities, images areloaded into special heap areas• Only classes are converted, resources left untouched in JAR file> Keep the original JAR on the classpath• Converted images must form a prefix of classpath• Conversion-time prefix must match the run-time prefix• Caution: if a library JAR file is updated, its binary image and alldependent images must be regenerated• Source code:> cldc/src/vm/share/ROM/BinaryROMWriter.cpp> cldc/src/vm/share/ROM/BinaryObjectWriter.cpp> midp/src/ams/app_image_gen/reference/classes/com/sun/midp/main/MIDletAppImageGenerator.java> midp/src/ams/ams_base_cldc/reference/native/midp_run.c33


AOT-compiler• Ahead-of-time compilation> Saves on compilation time> Saves RAM space> More expensive optimizations can be applied• AOT-compilation for system classes> Selected methods of romized system classes– profile on typical applications to select> Performed as a part of class optimization during ROM imagegeneration> Controlled with Precompile directive of ROMizer configurationfile34


AOT-compilation of DownloadedClasses• Performed during Monet conversion• Method selection> AMS shall implement J<strong>VM</strong>SPI_IsPrecompilationTarget() tochoose methods to precompile> During conversion, <strong>VM</strong> calls this function for every method andcompiles precompilation targets35


Q & AOleg PlissSun Microsystems36

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!