Let s make some Marc R. Hoffmann Eclipse Summit Europe

Similar documents
Programming Language Systems

javac 29: pop 30: iconst_0 31: istore_3 32: jsr [label_51]

Under the Hood: The Java Virtual Machine. Problem: Too Many Platforms! Compiling for Different Platforms. Compiling for Different Platforms

JVML Instruction Set. How to get more than 256 local variables! Method Calls. Example. Method Calls

The Java Virtual Machine. CSc 553. Principles of Compilation. 3 : The Java VM. Department of Computer Science University of Arizona

301AA - Advanced Programming [AP-2017]

Compiling for Different Platforms. Problem: Too Many Platforms! Dream: Platform Independence. Java Platform 5/3/2011

CSCE 314 Programming Languages

CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs. Compiling Java. The Java Class File Format 1 : JVM

JVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format

Course Overview. PART I: overview material. PART II: inside a compiler. PART III: conclusion

Under the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008

Muggl: The Muenster Generator of Glass-box Test Cases

The Java Virtual Machine Specification. Release 1.0 Beta DRAFT

to perform dependence analysis on Java bytecode, we must extend existing dependence analysis techniques for adapting Java bytecode. In this paper we p

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE

Translating Java bytecode to Simple

A Quantitative Analysis of Java Bytecode Sequences

COMP3131/9102: Programming Languages and Compilers

301AA - Advanced Programming [AP-2017]

Reverse Engineering of Managed Languages

Over-view. CSc Java programs. Java programs. Logging on, and logging o. Slides by Michael Weeks Copyright Unix basics. javac.

Problem: Too Many Platforms!

COMP 321: Introduction to Computer Systems

CSC 4181 Handout : JVM

An Introduction to Multicodes. Ben Stephenson Department of Computer Science University of Western Ontario

This project is supported by DARPA under contract ARPA F C-0057 through a subcontract from Syracuse University. 2

A dozen instructions make Java bytecode 1

Compiling Techniques

Code Generation COMP 520: Compiler Design (4 credits) Professor Laurie Hendren

Compilation 2012 Code Generation

CS2110 Fall 2011 Lecture 25. Under the Hood: The Java Virtual Machine, Part II

COMP3131/9102: Programming Languages and Compilers

The Java Virtual Machine

Compiler construction 2009

JAM 16: The Instruction Set & Sample Programs

Delft-Java Dynamic Translation

The Java Virtual Machine

Improving Java Performance

Java Card 2.1 Virtual Machine Specification

Tracking Data Dependence of Large-scale Systems for Practical Program Understanding

Bytecode Support for the Universe Type System. Alex Suzuki

Tutorial 3: Code Generation

Improving Java Code Performance. Make your Java/Dalvik VM happier

Code Generation Introduction

Michael Rasmussen ZeroTurnaround

Java Card Platform. Virtual Machine Specification, Classic Edition. Version 3.1. January 2019

Virtual Machine Design

301AA - Advanced Programming

CS263: Runtime Systems Lecture: High-level language virtual machines. Part 1 of 2. Chandra Krintz UCSB Computer Science Department

Java byte code verification

CMPSC 497: Java Security

Characterizing the SPEC JVM98 Benchmarks On The Java Virtual Machine

Part VII : Code Generation

Jaos - Java on Aos. Oberon Event 03 Patrik Reali

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

Static Program Analysis

How do you create a programming language for the JVM?

Time-Predictable Memory Arbitration for a Java Chip-Multiprocessor

Recap: Printing Trees into Bytecodes

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

An Analysis of Basic Blocks within SPECjvm98 Applications

Java Class Loading and Bytecode Verification

JAVA BYTECODE TO PILAR TRANSLATOR VIDIT OCHANI. B.E., Rajiv Gandhi Technical University, 2011 A REPORT

COMP 520 Fall 2009 Virtual machines (1) Virtual machines

Taming the Java Virtual Machine. Li Haoyi, Chicago Scala Meetup, 19 Apr 2017

Advice Weaving in ÉNFASIS

Dalvik VM Internals. Dan Bornstein Google

Topics. Structured Computer Organization. Assembly language. IJVM instruction set. Mic-1 simulator programming

Real-world abstract machines

Java Instrumentation for Dynamic Analysis

In Vogue Dynamic. Alexander Shopov

Living in the Matrix with Bytecode Manipulation

Java Code Coverage Mechanics. by Evgeny Mandrikov at EclipseCon Europe 2017

Scala: Byte-code Fancypants. David Pollak JVM Language Summit 2009

Shared Mutable State SWEN-220

Run-time Program Management. Hwansoo Han

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16

Introduction to Compiler Construction in a Java World

Exercise 7 Bytecode Verification self-study exercise sheet

Java Code Coverage Mechanics Evgeny Mandrikov Marc Hoffmann #JokerConf 2017, Saint-Petersburg

VIRTUAL EXECUTION ENVIRONMENTS

A Quantitative Analysis of the Performance Impact of Specialized Bytecodes in Java

CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs. Getting started... Getting started. 2 : Java Bytecode BCEL

CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs

CSc 372 Comparative Programming Languages. Getting started... Getting started. B: Java Bytecode BCEL

02 B The Java Virtual Machine

CS 326 Programming Languages. The Espresso Virtual Machine

COMP 520 Fall 2013 Code generation (1) Code generation

Compiling Faster, Compiling Better with Falcon. Iván

Exploiting FPGA Concurrency to Enhance JVM Performance

JPF Lab Formal Methods Summer School 2011 Menlo College

Code Generation: Introduction

Java and C II. CSE 351 Spring Instructor: Ruth Anderson

Compiler construction 2009

Jlint status of version 3.0

Implementing on Object-Oriented Language 2.14

Today. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time

Plan for Today. Safe Programming Languages. What is a secure programming language?

Java Code Coverage Mechanics

Transcription:

Let s make some Marc R. Hoffmann Eclipse Summit Europe 2012 24.10.2012

public class WhatIsFaster { int i; void inc1() { i = i + 1; } void inc2() { i += 1; } void inc3() { i++; } }

Why? Compilers Scrip;ng Engines Sta;c Analysis Dynamic Analysis Reverse Engineering Read Write

ca fe ba be 00 00 00 33 00 17 07 00 02 01 00 0c 57 68 61 74 49 73 46 61 73 74 65 72 07 00 04 01 00 10 6a 61 76 61 2f 6c 61 6e 67 2f 4f 62 6a 65 63 74 01 00 01 69 01 00 01 49 01 00 06 3c 69 6e 69 74 3e 01 00 03 28 29 56 01 00 04 43 6f 64 65 0a 00 03 00 0b 0c 00 07 00 08 01 00 0f 4c 69 6e 65 4e 75 6d 62 65 72 54 61 62 6c 65 01 00 12 4c 6f 63 61 6c 56 61 72 69 61 62 6c 65 54 61 62 6c 65 01 00 04 74 68 69 73 01 00 0e 4c 57 68 61 74 49 73 46 61 73 74 65 72 3b 01 00 04 69 6e 63 31

Versions 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 45.0 45.3 46.0 47.0 48.0 49.0 50.0 51.0 The JVM Spec First Edi;on The JVM Spec Second Edi;on The JVM Spec Java 7 SE Edi;on

Class File Naming java/lang/string.class java/util/map$entry.class Java/util/Collections$1.class

JVM Type Nota<on Base Types Z C B S I J F D V Object Types Ljava/lang/String; Array Types: [C [[Z [Ljava/lang/String;

ClassFile { u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[]; u2 fields_count; field_info fields[]; u2 methods_count; method_info methods[]; u2 attributes_count; attribute_info attributes[]; }

Class File Anatomy Class Constant Pool Fields ASributes Methods ASributes ASributes

Constant Pool Idx Idx Idx Idx Idx Idx Idx Idx u1 tag; u1[] info u1 tag; u1[] info u1 tag; u1[] info u1 tag; u1[] info u1 tag; u1[] info u1 tag; u1[] info u1 tag; u1[] info u1 tag; u1[] info Constant Pool Fields Methods

Constant Pool FieldRef MethodRef IntfMethRef String Class NameAndType 2 Utf8 Integer Float Long Double Constant Pool Fields Methods MethodHandle, MethodType, InvokeDynamic

Fields field_info { u2 access_flags; u2 name_index; Utf8 u2 descriptor_index; Utf8 u2 attributes_count; attribute_info attributes[]; } Constant Pool Fields Methods

ConstantValue AAribute Contant Pool int, short, char, byte, boolean float long double java.lang.string Integer Float Long Double String Constant Pool Fields Methods

Methods method_info { u2 access_flags; Utf8 u2 name_index; u2 descriptor_index; Utf8 u2 attributes_count; attribute_info attributes[]; } Where is the Code? getvalue run <init> <clinit> ()I ()V (LFoo;)V (II)I; Constant Pool Fields Methods

Code AAribute Code_attribute { u2 attribute_name_index; u4 attribute_length; u2 max_stack; u2 max_locals; u4 code_length; u1 code[]; u2 exception_table_length; { u2 start_pc; u2 end_pc; u2 handler_pc; u2 catch_type; } exception_table[]; u2 attributes_count; attribute_info attributes[]; }

void inc1() { i = i + 1; } 19 00 ALOAD 0 59 DUP B4 nn nn GETFIELD WhatIsFaster.i 04 ICONST_1 60 IADD B5 nn nn PUTFIELD WhatIsFaster.i B1 RETURN

Data Operand Stack Local Variables this Methods Args Local Vars References get/put field invoke new

Operand Stack ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN

Operand Stack ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN this

Operand Stack ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN this this

Operand Stack ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN i this

Operand Stack ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN 1 i this

Operand Stack ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN i+1 this

Operand Stack ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN

Stack Frame Max Locals Max Stack 1 i this

205 Opcodes I Constants NOP ACONST_NULL ICONST_n LCONST_n FCONST_n DCONST_n BIPUSH SIPUSH LDC LDC_W LDC2_W Loads ILOAD LLOAD FLOAD DLOAD ALOAD IALOAD LALOAD FALOAD DALOAD AALOAD BALOAD Stores ISTORE LSTORE FSTORE DSTORE ASTORE IASTORE LASTORE FASTORE DASTORE AASTORE BASTORE

205 Opcodes II References GETSTATIC PUTSTATIC GETFIELD PUTFIELD INVOKExxx NEWARRAY ANEWARRAY ATHROW CHECKCAST INSTANCEOF MONITORENTER MONITOREXIT Control GOTO TABLESWITCH LOOKUPSWITCH xreturn IFEQ IFNE IFLT IFGE IFGT IFLE IFNULL IFNONNULL Comparison LCMP FCMPL FCMPG DCMPL DCMPG

Byte Code Tools javap Byte Code Outline Plug- in asm.objectweb.org

JVM Data Types top oneword twoword int float reference long double uninitialized Object Java Class Hierachy

Stack Map Frames L0: ILOAD 3 ISTORE 4 ILOAD 1 IFEQ L1 ILOAD 3 ICONST_2 IMUL ISTORE 3 L1: ILOAD 2 IFEQ L2 IINC 3 L2: ILOAD 4 IRETURN Locals Stack

Debug AAributes Class SourceFile Methods LineNumberTable LocalVariableTable LocalVariableTypeTable

What is Faster? void inc1() { } i = i + 1; void inc2() { } i += 1; void inc3() { } i++; ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN ALOAD 0 DUP GETFIELD WhatIsFaster.i ICONST_1 IADD PUTFIELD WhatIsFaster.i RETURN

Thank You! Ques<ons? Please Vote! Marc R. Hoffmann Eclipse Summit Europe 2012 24.10.2012