slides - Institute of Computer Engineering (E182)

Download Report

Transcript slides - Institute of Computer Engineering (E182)

IBM Software Group
Tactics for Minimal Interference from Class
Loading in Real-Time Java™
Sean Foley, IBM Software Group, Ottawa, Canada
[email protected] 613-726-5516
The 5th International Workshop on Java
Technologies for Real-time and Embedded
Systems - JTRES 2007
Institute of Computer Engineering
Vienna University of Technology
Vienna, Austria
September 26, 2007
© 2007 IBM Corporation
IBM Software Group
Agenda
 Motivations for altering class loading behaviour in
Real-Time Java
 Tactics, experiences, results:
– Reducing the size and number of classes to load
– Elimination of premature loading
– Redistribution of loading
– Elimination of repeated loading
– Alternative class formats
 Requirements for Implementation of Techniques
2
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Loading Takes Time
3
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Motivations and Rationale
 Class Loading Impacts Real-Time Requirements
 Simplest approach: load everything at startup
– Can be optimized
– Not necessarily easy (code paths, development)
– Can be excessive (memory/time), particularly for large apps.
– Not all classes needed for each invocation
 Startup time possibly subject to timing constraints
 Alternative approaches beneficial for optimal usage of
resources
4
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Instantiated Type Analysis (ITA) determines what methods
and classes can be removed
Basic control flow analysis follows
all references with the code
5
ITA instantiates objects for
more accurate analysis to
determine reachable items
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Advanced Control Flow Analysis
ITA control flow analysis involves exception object throwing
and virtual method invocations
6
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Elimination of loading Induced by Verification
 Runtime bytecode verifier loads classes to verify inheritance.
 Can be avoided by inserting checkcast bytecodes.
Operation
Verifier requirement
Non-static field access or method invocation Receiver must be subtype of declaring class of field/method
Field store
Stored object must be subtype of field type
Method invocation
Arguments must be subtypes of parameters
Return instruction
Returned object must be subtype of return type
Throw instruction or exception handler
Thrown or caught object must be Throwable
Example:
static BaseClass aMethod(SubClass subClass) {
if(subClass == null) throw (Throwable) new NullPointerException();
return (BaseClass) subClass;
}
Bytecodes:
7
aload_0 aconst_null ifnull new invokespecial
checkcast
athrow aload_0
checkcast
areturn
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Cold Method Refactoring: Distributed Loading
The most expensive stage of loading
is bytecode verification.
Refactoring steps:
1. Identify a method to be migrated
2. Create a counterpart static method in a
shell class
3. Migrate the body of the original method
4. Replace the method body with an
invocation of the counterpart
Result:
 Bytecode verification of the original
method is delayed
 Loading time of original class is split
8
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Persistent Class Sharing
 Class representations shared amongst VMs: concurrently, sequentially
 Cache can exist in shared memory or on file system
 Share: classes, strings, compiled code
 Not everything shareable: constraints from verifier, advanced optimizations
23377
20455
Sharing w ith
Warm Cache
17533
No Sharing
14611
0
11689
Sharing
w ith Warm
Cache
10000
8767
Sharing
w ith Cold
Cache
60
40
20
0
20000
5845
No Sharing
30000
Maximum Load Time
2923
600
500
400
300
200
100
0
Abs. Max. Time for a Single Class
Load
1
Average Time per Class Load
Time
(microseconds)
Time (microseconds)
 Multiple shared caches more flexible
Tim e (m icroseconds)
Sharing Warm Cache
No Sharing
IBM LS20 Blade Server / real-time linux / IBM Java5 VM
9
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Alternative File Formats
 Load precompiled native code (AOT or ahead-of-time)
 With IBM’s WebSphere Real-Time, the steps are:
Other
jar files
Source
files
Compile
Compile
Java
AOT
Jar files
Run
Bound
jar files
Real-time
execution
 Other class file formats have been designed
 The class file format specification itself allows the delivery of
additional data
10
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation
IBM Software Group
Summary
 Class Loading can Interference with Real-Time Constraints
 Tactics to alter loading:
– Reducing the size and number of classes to load
– Elimination of premature loading
– Temporal redistribution of loading
– Elimination of repeated loading
– Alternative methods of loading
 Implementation require analysis, tuning, building, some
insight into the app
 Tools and resources are available for implementation
11
Tactics for Minimal Interference from Class Loading in Real-Time Java | JTRES 2007
© 2007 IBM Corporation