SlideShare a Scribd company logo
eval4j
compiling expressions to be
evaluated by the debugger
andrey.breslav@ .com
Eval4j @ JVMLS 2014
Stop at a
breakpoint
Inspect memoryInspect call stacks
Evaluate given
expression
Evaluate given
expression
Eval4j @ JVMLS 2014
Working Horse: Bare JDI
• Access Variables
• Access Fields
• Call Methods
• No Evaluate Expression
out-of-the-box
How it’s done for Java
• IntelliJ has an intepreter for Java expressions
– written from scratch
– yet another definition of semantics
– may disagree with the compiler’s semantics
• Well, IntelliJ’s not very intimate with javac
When you have your own compiler?
• Eclipse Java DT still has an interpreter
• Scala IDE (Eclipse) — no Evaluate Expression
• Ceylon IDE (Eclipse) — no Evaluate Expression
• There’s some room for improvement…
Reuse the Compiler (Take 1)
a + b
.class
file
Debugee
process
compile
load
run
Eval4j: Bytecode Interpreter
• foo.x + 2
– ALOAD 1
– GETFIELD Foo.x : I
– ICONST_2
– IADD
– INVOKESTATIC kotlin/io/IoPackage.println (I)V
• https://github.com/abreslav/eval4j
• Re-uses ASM’s Interpreter
Compiling an expression
free variables
Extract Method Refactoring
Summary so far
Extract Method
+
Compiler
+
eval4j
=
Evaluate Expression
Challenge: Lambdas/Anonymous
Classes
• Not supported for Java/Scala
• Problems:
– New class that is not available in the debugee
process
– That class may access privates that it’s not allowed
to access
Challenge: New Classes
private?
• Also: How do you load a class into the
debugee?
Loading a class…
• protected Class<?> defineClass(byte[], …)
How Privates Work Normally
• Special synthetic accessor methods
– INVOKESTATIC Foo.access$001()
– can’t insert a new method into the outer class
Prepare the methods of the lambda
• Evaluate the body of the method
public Object invoke() {
Object result = null;
Throwable exception = null;
if (exception == null)
return result;
else throw exception;
}
What happens to your thread
• You stopped on a bp1
• You evaluated an expression
– Set another bp
– Stopped on it
– Computed something
– Resulmed
– => you are not on bp1 any more
Workaround
• Start a special thread
while (true) {
nop();
}
• To stop:
boolean done = false;
while (!done) {
nop();
}
Summary
• Prerequisites
– Extract method
– Ability to compile with some tweaks
• Results
– Any expressions/statements
– Lambdas/local classes
• Use it for your language!
– https://github.com/abreslav/eval4j

More Related Content

PPTX
Language Design Trade-offs
PDF
Kotlin: Challenges in JVM language design
PDF
Kotlin Slides from Devoxx 2011
PDF
A quick and fast intro to Kotlin
PPT
The Kotlin Programming Language
PDF
Kotlin - Better Java
PDF
Kotlin advanced - language reference for android developers
PPTX
Introduction to Kotlin Language and its application to Android platform
Language Design Trade-offs
Kotlin: Challenges in JVM language design
Kotlin Slides from Devoxx 2011
A quick and fast intro to Kotlin
The Kotlin Programming Language
Kotlin - Better Java
Kotlin advanced - language reference for android developers
Introduction to Kotlin Language and its application to Android platform

What's hot (20)

PDF
Smart Migration to JDK 8
PDF
Introduction to Kotlin JVM language
PDF
Taking Kotlin to production, Seriously
PDF
Specialized Compiler for Hash Cracking
PDF
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
PDF
Swift and Kotlin Presentation
PDF
Android antipatterns
PDF
Introduction to the Java bytecode - So@t - 20130924
PPTX
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
PDF
Kotlin boost yourproductivity
PDF
Kotlin Overview
PPTX
Getting Started With Kotlin
PDF
Building microservices with Kotlin
PDF
Code lifecycle in the jvm - TopConf Linz
PDF
What to expect from Java 9
PPTX
Kotlin
PPTX
Ahead-Of-Time Compilation of Java Applications
PDF
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
PDF
Kotlin Developer Starter in Android projects
ODP
Enrich Your Models With OCL
Smart Migration to JDK 8
Introduction to Kotlin JVM language
Taking Kotlin to production, Seriously
Specialized Compiler for Hash Cracking
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Swift and Kotlin Presentation
Android antipatterns
Introduction to the Java bytecode - So@t - 20130924
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
Kotlin boost yourproductivity
Kotlin Overview
Getting Started With Kotlin
Building microservices with Kotlin
Code lifecycle in the jvm - TopConf Linz
What to expect from Java 9
Kotlin
Ahead-Of-Time Compilation of Java Applications
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
Kotlin Developer Starter in Android projects
Enrich Your Models With OCL
Ad

Viewers also liked (20)

PPTX
Kotlin
PDF
Fun with Kotlin
PPTX
Kotlin for Android: Brief and Clear
PDF
Functions and data
PDF
Kotlin: Incompetence * Motivation = Innovation?
PDF
JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation
PPTX
Kotlin (Introduction for students)
PDF
[JVMLS 12] Kotlin / Java Interop
PPTX
Kotlin gets Reflection
PDF
Kotlin @ StrangeLoop 2011
PDF
Kotlin @ CSClub & Yandex
PPTX
Flexible Types in Kotlin - JVMLS 2015
PDF
Kotlin @ Devoxx 2011
PPTX
Introduction to Kotlin: Brief and clear
PDF
JVMLS 2016. Coroutines in Kotlin
PDF
Светлана Исакова «Язык Kotlin»
PDF
Be More Productive with Kotlin
PDF
Who's More Functional: Kotlin, Groovy, Scala, or Java?
PPTX
Category theory, Monads, and Duality in the world of (BIG) Data
PDF
Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...
Kotlin
Fun with Kotlin
Kotlin for Android: Brief and Clear
Functions and data
Kotlin: Incompetence * Motivation = Innovation?
JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation
Kotlin (Introduction for students)
[JVMLS 12] Kotlin / Java Interop
Kotlin gets Reflection
Kotlin @ StrangeLoop 2011
Kotlin @ CSClub & Yandex
Flexible Types in Kotlin - JVMLS 2015
Kotlin @ Devoxx 2011
Introduction to Kotlin: Brief and clear
JVMLS 2016. Coroutines in Kotlin
Светлана Исакова «Язык Kotlin»
Be More Productive with Kotlin
Who's More Functional: Kotlin, Groovy, Scala, or Java?
Category theory, Monads, and Duality in the world of (BIG) Data
Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...
Ad

Similar to Eval4j @ JVMLS 2014 (20)

PPTX
The Road to Lambda - Mike Duigou
PPTX
SOLID principles
PPTX
Metaprogramming in Ruby
PPT
Introduction to oops
PPTX
C++ Testing Techniques Tips and Tricks - C++ London
PPTX
12_oop templa.pptx
PPTX
Test in action – week 1
PDF
DSL's with Groovy
PDF
Yapc10 Cdt World Domination
PDF
pull requests I sent to scala/scala (ny-scala 2019)
PPT
Chapter10_Data_Abstraction_and_Object_Orientation_4e.ppt
ODP
Synapseindia reviews.odp.
PPT
08-classes-objects.ppt
PPT
08-classes-objects.ppt
PPT
Python - Classes and Objects, Inheritance
PPT
OOC in python.ppt
PPTX
Java Programming and J2ME: The Basics
KEY
Java Closures
PPT
Data abstraction and object orientation
KEY
Polyglot and Functional Programming (OSCON 2012)
The Road to Lambda - Mike Duigou
SOLID principles
Metaprogramming in Ruby
Introduction to oops
C++ Testing Techniques Tips and Tricks - C++ London
12_oop templa.pptx
Test in action – week 1
DSL's with Groovy
Yapc10 Cdt World Domination
pull requests I sent to scala/scala (ny-scala 2019)
Chapter10_Data_Abstraction_and_Object_Orientation_4e.ppt
Synapseindia reviews.odp.
08-classes-objects.ppt
08-classes-objects.ppt
Python - Classes and Objects, Inheritance
OOC in python.ppt
Java Programming and J2ME: The Basics
Java Closures
Data abstraction and object orientation
Polyglot and Functional Programming (OSCON 2012)

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
Programs and apps: productivity, graphics, security and other tools
Advanced methodologies resolving dimensionality complications for autism neur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Diabetes mellitus diagnosis method based random forest with bat algorithm
sap open course for s4hana steps from ECC to s4
Mobile App Security Testing_ A Comprehensive Guide.pdf
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Chapter 3 Spatial Domain Image Processing.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Weekly Chronicles - August'25 Week I
Spectral efficient network and resource selection model in 5G networks
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Eval4j @ JVMLS 2014

  • 1. eval4j compiling expressions to be evaluated by the debugger andrey.breslav@ .com
  • 3. Stop at a breakpoint Inspect memoryInspect call stacks
  • 6. Working Horse: Bare JDI • Access Variables • Access Fields • Call Methods • No Evaluate Expression out-of-the-box
  • 7. How it’s done for Java • IntelliJ has an intepreter for Java expressions – written from scratch – yet another definition of semantics – may disagree with the compiler’s semantics • Well, IntelliJ’s not very intimate with javac
  • 8. When you have your own compiler? • Eclipse Java DT still has an interpreter • Scala IDE (Eclipse) — no Evaluate Expression • Ceylon IDE (Eclipse) — no Evaluate Expression • There’s some room for improvement…
  • 9. Reuse the Compiler (Take 1) a + b .class file Debugee process compile load run
  • 10. Eval4j: Bytecode Interpreter • foo.x + 2 – ALOAD 1 – GETFIELD Foo.x : I – ICONST_2 – IADD – INVOKESTATIC kotlin/io/IoPackage.println (I)V • https://github.com/abreslav/eval4j • Re-uses ASM’s Interpreter
  • 11. Compiling an expression free variables Extract Method Refactoring
  • 12. Summary so far Extract Method + Compiler + eval4j = Evaluate Expression
  • 13. Challenge: Lambdas/Anonymous Classes • Not supported for Java/Scala • Problems: – New class that is not available in the debugee process – That class may access privates that it’s not allowed to access
  • 14. Challenge: New Classes private? • Also: How do you load a class into the debugee?
  • 15. Loading a class… • protected Class<?> defineClass(byte[], …)
  • 16. How Privates Work Normally • Special synthetic accessor methods – INVOKESTATIC Foo.access$001() – can’t insert a new method into the outer class
  • 17. Prepare the methods of the lambda • Evaluate the body of the method public Object invoke() { Object result = null; Throwable exception = null; if (exception == null) return result; else throw exception; }
  • 18. What happens to your thread • You stopped on a bp1 • You evaluated an expression – Set another bp – Stopped on it – Computed something – Resulmed – => you are not on bp1 any more
  • 19. Workaround • Start a special thread while (true) { nop(); } • To stop: boolean done = false; while (!done) { nop(); }
  • 20. Summary • Prerequisites – Extract method – Ability to compile with some tweaks • Results – Any expressions/statements – Lambdas/local classes • Use it for your language! – https://github.com/abreslav/eval4j