Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03....
Transcript of Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03....
![Page 1: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/1.jpg)
Ola Binicomputational metalinguist
[email protected]://olabini.com/blog
Adopting the JVM
onsdag, 2010 november 03
![Page 2: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/2.jpg)
From Sweden to Chicago through ThoughtWorks
Language geek at ThoughtWorks
JRuby core developer, Ioke and Seph creator
Member of the JSR 292 EG
Your host
onsdag, 2010 november 03
![Page 3: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/3.jpg)
Demographics
onsdag, 2010 november 03
![Page 4: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/4.jpg)
SmorgasbordWhys and wherefores
How to get started
Polyglot patterns
Interoperability
JVM tweaks and tools
Bytecode
JSR 292
Politics
onsdag, 2010 november 03
![Page 5: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/5.jpg)
Why the JVM?Fantastic platform
JIT
Memory model and GC
Threading
Libraries
Tools
Runs mostly anywhere
Interoperability between languages
Many interesting languages already available
onsdag, 2010 november 03
![Page 6: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/6.jpg)
Why not Java?More ceremony than essence
Verbosity
Slow turnaround
Compile time cycle
Abstraction level
Expressivity
Rate of change
Useful libraries in other languages
onsdag, 2010 november 03
![Page 7: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/7.jpg)
Sapir-Whorf
onsdag, 2010 november 03
![Page 8: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/8.jpg)
onsdag, 2010 november 03
![Page 9: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/9.jpg)
Programming languagesIverson - “Notation as a tool of thought”
Paul Graham - The Blub paradox
Ruby - Matz says one inspiration was novel Babel-17
Steve Yegge - The difference between recursion and iteration
onsdag, 2010 november 03
![Page 10: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/10.jpg)
Where do you start?
onsdag, 2010 november 03
![Page 11: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/11.jpg)
Adopting a new languageChoose with care
Be strategic about language use
Productivity bump
New syntax and new libraries
But also new ways of thinking
Leverage should increase quickly
Not that different from learning a new framework
onsdag, 2010 november 03
![Page 12: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/12.jpg)
Polyglot Patterns
onsdag, 2010 november 03
![Page 13: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/13.jpg)
Architecture
onsdag, 2010 november 03
![Page 14: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/14.jpg)
onsdag, 2010 november 03
![Page 15: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/15.jpg)
onsdag, 2010 november 03
![Page 16: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/16.jpg)
onsdag, 2010 november 03
![Page 17: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/17.jpg)
Polyglot TestingScala, Clojure, Ruby, Groovy, etc
All of these can test Java code very well
Quicker turnaround
More manageable tests
Use libraries from test language (RSpec, Erjang QuickCheck)
Approaches
Exploratory testing - REPL
Unit and functional testing
Acceptance testing - Cucumber
onsdag, 2010 november 03
![Page 18: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/18.jpg)
import org.thoughtworks.PrimeFinder
describe PrimeFinder do it "finds the next prime number" do pf = PrimeFinder.from(10) pf.next.should == 11
pf = PrimeFinder.from(25) pf.next.should == 29 endend
onsdag, 2010 november 03
![Page 19: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/19.jpg)
import(org:thoughtworks:PrimeFinder)
forAll(natural n, pf = PrimeFinder from(n) pf next should be odd)
onsdag, 2010 november 03
![Page 20: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/20.jpg)
Build ScriptingIs Maven or Ant the best way to build your system?
BuildR
GAnt
Polyglot Maven
General build scripts
onsdag, 2010 november 03
![Page 21: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/21.jpg)
includeTargets << gant.targets.CleancleanPattern << [ '**/*~' , '**/*.bak' ]cleanDirectory << 'build'
target ( stuff : 'A target to do some stuff.' ) { println ( 'Stuff' ) depends ( clean ) echo ( message : 'A default message from Ant.' ) otherStuff ( )}
target ( otherStuff : 'A target to do some other stuff' ) { println ( 'OtherStuff' ) echo ( message : 'Another message from Ant.' ) clean ( )}
setDefaultTarget ( stuff )
onsdag, 2010 november 03
![Page 22: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/22.jpg)
Alien LibrariesX library consumed by Java
Depends on how the language exposes Java functionality
Java library consumed by X
Using Xs Java Integration features
Sometimes complicates build process
onsdag, 2010 november 03
![Page 23: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/23.jpg)
(.. System (getProperties) (get "os.name"))
onsdag, 2010 november 03
![Page 24: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/24.jpg)
Service InjectionUsing DI to compose languages
Spring has ScriptFactory
Allows implementation of any interface in most languages
onsdag, 2010 november 03
![Page 25: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/25.jpg)
package com.thoughtworks;
public interface Animal { void run();}
class Fox def run puts "Running away!" endend
Fox.new
onsdag, 2010 november 03
![Page 26: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/26.jpg)
<?xml version="1.0" encoding="utf-8"?>
<beans> <bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor" />
<bean id="fox" class="org.springframework.scripting.jruby.JRubyScriptFactory"> <constructor-arg value="file:fox.rb" /> <constructor-arg value="com.thoughtworks.Animal" /> </bean></beans>
onsdag, 2010 november 03
![Page 27: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/27.jpg)
End User ScriptingMake it possible to customize behaviour
Save/Load scripts
Expose a model to the scripts
How much of the application can be implemented like this?
Versioning
onsdag, 2010 november 03
![Page 28: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/28.jpg)
Java as the C of the JVMUse another language as the main language
Drop down to Java
Performance
Features that top level doesn’t have
To bind things together
onsdag, 2010 november 03
![Page 29: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/29.jpg)
MOPping
onsdag, 2010 november 03
![Page 30: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/30.jpg)
BSF
onsdag, 2010 november 03
![Page 31: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/31.jpg)
JLabel mylabel = new JLabel();BSFManager.registerScriptingEngine("ruby", "org.jruby.javasupport.bsf.JRubyEngine", new String[] { "rb" });
BSFManager manager = new BSFManager();manager.declareBean("label", mylabel, JFrame.class);manager.exec("ruby", "(java)", 1, 1, "$label.setText(\"This is a test.\")");
onsdag, 2010 november 03
![Page 32: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/32.jpg)
JSR 223
onsdag, 2010 november 03
![Page 33: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/33.jpg)
ScriptEngineManager m = new ScriptEngineManager();ScriptEngine rubyEngine = m.getEngineByName("jruby");ScriptContext context = rubyEngine.getContext();
context.setAttribute("label", new Integer(4), ScriptContext.ENGINE_SCOPE);
try { rubyEngine.eval("puts 2 + $label", context);} catch(ScriptException e) { e.printStackTrace();}
onsdag, 2010 november 03
![Page 34: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/34.jpg)
Dynamic MOP
onsdag, 2010 november 03
![Page 35: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/35.jpg)
JVM Tweaking
onsdag, 2010 november 03
![Page 36: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/36.jpg)
The basic flags-server, -client
-Xmx, -Xms, -Xss
-Xverify:none
-XX:PermSize=512m
-XX:MaxPermSize=512m
onsdag, 2010 november 03
![Page 37: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/37.jpg)
What’s happening with GC?-XX:+PrintGC
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails
onsdag, 2010 november 03
![Page 38: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/38.jpg)
What’s happening with JITting?-XX:+PrintCompilation
-XX:+PrintInlining (debug build only)
-XX:+PrintOptoAssembly (debug build only)
-XX:+PrintAssembly (debug build only)
-XX:+UnlockDiagnosticVMOptions
-XX:+PrintNMethods
-XX:+PrintSignatureHandlers
onsdag, 2010 november 03
![Page 39: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/39.jpg)
Other diagnostics-XX:+HeapDumpOnOutOfMemoryError
-XX:+TraceClassLoading
-XX:+TraceClassUnloading
-XX:+TraceClassLoadingPreorder
-XX:+TraceClassResolution
onsdag, 2010 november 03
![Page 40: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/40.jpg)
Tuning-XX:+AggressiveOpts
-XX:+UseCompressedOops (for x64 versions)
-XX:+DoEscapeAnalysis
-XX:CompileThreshold=n (default 10000)
-XX:NewRatio=5
-XX:ParallelGCThreads=2
onsdag, 2010 november 03
![Page 41: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/41.jpg)
More information here:
http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
onsdag, 2010 november 03
![Page 42: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/42.jpg)
JVM Tools
onsdag, 2010 november 03
![Page 43: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/43.jpg)
JMX
onsdag, 2010 november 03
![Page 44: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/44.jpg)
JConsole
onsdag, 2010 november 03
![Page 45: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/45.jpg)
VisualVM
onsdag, 2010 november 03
![Page 46: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/46.jpg)
Eclipse Memory Analyzer
onsdag, 2010 november 03
![Page 47: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/47.jpg)
JVM Bytecode
onsdag, 2010 november 03
![Page 48: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/48.jpg)
ASM
onsdag, 2010 november 03
![Page 49: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/49.jpg)
BiteScript
onsdag, 2010 november 03
![Page 50: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/50.jpg)
JSR 292
onsdag, 2010 november 03
![Page 51: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/51.jpg)
Method handlesA pointer to a Java method
As fast to invoke as calling the method directly
No introspection available - it’s an opaque stateless object
Combinator based library around them
Capability based
Security check at lookup, not at invocation
If you have the object you can call it
onsdag, 2010 november 03
![Page 52: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/52.jpg)
MH catchException(MH target, Class exType, MH handler)
MH collectArguments(MH target, MethodType newType)
MH convertArguments(MH target, MethodType newType)
MH dropArguments(MH target, int pos, Class... valueTypes)
MH filterArguments(MH target, MH... filters)
MH foldArguments(MH target, MH combiner)
MH guardWithTest(MH test, MH target, MH fallback)
MH insertArguments(MH target, int pos, Object... values)
MH spreadArguments(MH target, MethodType newType)
Method handle combinators
onsdag, 2010 november 03
![Page 53: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/53.jpg)
MethodType type = MethodType.methodType(void.class, String.class);MethodHandle handle = MethodHandles.lookup().findVirtual(PrintStream.class, "print", type);handle.invokeExact(System.out, "Hello method handles\n");
onsdag, 2010 november 03
![Page 54: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/54.jpg)
Neat trick
public static void sayClassName() { String name = MethodHandles.lookup().lookupClass().getName(); System.err.println(name);}
onsdag, 2010 november 03
![Page 55: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/55.jpg)
Invoke DynamicNew byte code
For each call site - calls a bootstrap method
Bootstrap method defined per class (in general)
Returns a CallSite or MethodHandle that should be used
Usually a guardWithTest MethodHandle is expected
CallSites can be invalidated according to language specific conditions
InvokeDynamic interface that can be used to call any method with
onsdag, 2010 november 03
![Page 56: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/56.jpg)
@BootstrapMethod(value=DynTest.class, name="bootstrap")public final class DynTest { private static CallSite bootstrap(Class<?> theClass, String theName, MethodType theType) { MethodHandle mh = MethodHandles.lookup(). findStatic(DynTest.class, "generic", theType); CallSite cs = new CallSite(mh);
cs.setTarget(mh); return cs; }
public static String generic(String theArgument) { return theArgument + ": brought to you by DynTest.generic()"; }
public static void main(String[] theArgs) throws Exception { System.out.println((String)InvokeDynamic.bar("bar invoked dynamically")); }}
onsdag, 2010 november 03
![Page 57: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/57.jpg)
Java Politics
onsdag, 2010 november 03
![Page 58: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/58.jpg)
The JCP and JSRs
onsdag, 2010 november 03
![Page 59: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/59.jpg)
Apache Harmony
onsdag, 2010 november 03
![Page 60: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/60.jpg)
Java 7 delayed
onsdag, 2010 november 03
![Page 61: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/61.jpg)
Oracle sues Google
onsdag, 2010 november 03
![Page 62: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/62.jpg)
IBM joins OpenJDK
onsdag, 2010 november 03
![Page 63: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/63.jpg)
Doug Lea
onsdag, 2010 november 03
![Page 64: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/64.jpg)
Apple JDK deprecated
onsdag, 2010 november 03
![Page 65: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/65.jpg)
Java 7
onsdag, 2010 november 03
![Page 66: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/66.jpg)
Forking?
onsdag, 2010 november 03
![Page 67: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/67.jpg)
Oracle as Java steward
onsdag, 2010 november 03
![Page 68: Adopting the JVM€¦ · JVM tweaks and tools Bytecode JSR 292 Politics onsdag, 2010 november 03. Why the JVM? Fantastic platform JIT Memory model and GC Threading Libraries Tools](https://reader036.fdocuments.in/reader036/viewer/2022062605/5fd84c6fe572023eb45fb0fa/html5/thumbnails/68.jpg)
Questions?
OLA BINI
http://olabini.com
@olabini
onsdag, 2010 november 03