JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View...

29
Copyright 2007, Sun Microsystems, Inc 1 JVM Tool Interface (JVM TI) Implementation in HotSpot [email protected]

Transcript of JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View...

Page 1: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 1

JVM Tool Interface(JVM TI)

Implementation in HotSpot

[email protected]

Page 2: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 2

JVM TI Implementation – Overview

• Implementation issues• HotSpot implementation layers• Implementation details• Q & A

Page 3: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 3

Implementation Issues

• Capabilities• Early start-up• Multiple environments• Retransformation / Redefinition

Page 4: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 4

Implementation Issues: Capabilities

• Agent requests what capabilities it wants• Allows pay-for-what-you eat• Allows implementation subsets• Capabilities change VM configuration:

> interpreter, compiler, ...

• Dynamic configuration?

can_tag_objectscan_generate_field_modification_eventscan_get_owned_monitor_infocan_pop_framecan_redefine_classes

Page 5: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 5

Implementation Issues: Early start-up

• JVM TI agents start before VM initialized• JVM TI events can be sent before main()• VM in delicate states• Allows VM configuration

Page 6: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 6

Implementation Issues: Environments

• Each has its own JVM TI environment• Can be multiple environments in one VM• Each with its own capabilities, events, state, ...• Hidden from VM Core

Page 7: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 7

Implementation Issues: Redefinition

• Class redefinition allows an agent to replace the definition of an already loaded class

• Class retransformation allows an agent to transform an already loaded class

• Retransformation added in JDK6• Used for bytecode instrumentation

Page 8: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 8

Implementation: Layers

• User agent> JVM TI

• JVM TI View> jvmtiEnv.hpp

• JVM TI Implementation> jvmtiExport.hpp

• VM Core

Page 9: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 9

Implementation: Layers – JVM TI View

• Transitions from JVM TI (external C interface)• To HotSpot implementation of JVM TI

> HotSpot types> C++ calls

• Both interfaces and transition code generated> jvmti.h (JVM TI standard interface – C-interface)> jvmtiEnter.cpp (transition code)> jvmtiEnv.hpp (interface to HotSpot implementation)

Page 10: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 10

Implementation: Layers - jvmtiExport

• Communicate from JVM TI to the VM Core> Information that will be needed (capabilities)

> Thus what to preserve> Which events to send

• Send events from the VM Core• Shield JVM TI internals from VM Core

Page 11: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 11

Function Architecture

VM Core

JVM TI Implementation

JVM TI View JVMDI View

JVMTIAgent

JVMDIAgent

JVMDIJVMDI

JvmtiEnvJvmtiEnv

JvmtiExportJvmtiExport

JVM TIAgent

JVM TIAgent

JVMTIJVMTI

Page 12: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 12

JVM TIAgent

Function Flow

VM Core

JVM TI Implementation

JVM TI View JVMDI View

JVM TIAgent

JVMDIAgent

JVMTIJVMTI JVMDIJVMDI

JvmtiEnvJvmtiEnv

JvmtiExportJvmtiExport

Page 13: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 13

JVMTIAgent

JVMTIAgent

Event Architecture

VM Core

JVMTI Implementation

JVMDIAgent

JVMTIJVMTI JVMDIJVMDI

JvmtiExportJvmtiExport

Page 14: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 14

JVMTIAgent

JVMTIAgent

Event Flow

VM Core

JVMTI Implementation

JVMDIAgent

JVMTIJVMTI JVMDIJVMDI

JvmtiExportJvmtiExport

Page 15: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 15

Implementation Details

• Threads and Environments• Event Controller• Generated Code• Some interesting source files:

> jvmtiRedefineClasses.cpp> jvmtiClassFileReconstituter.cpp> jvmtiTagMap.cpp

Page 16: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 16

Thread / Environment Data

Per Thread All Threads

Per

En v

iron

men

tA

ll E

n vir

onm

ents

JvmtiEnvThreadState JvmtiEnv

JvmtiThreadState All other classes/data

... everything else ...

Global enablementEvent handlersCapabilities

Interpret only modeCurrent stack depth

Per thread enablementFrame pop info

Page 17: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 17

User Enabled

Event Controller

JvmtiEnv

Computed Enabled

JvmtiEventController

JvmtiExport

Method enter/exit

User EnableSet CallbacksNew EnvSet Frame Pop

Thread-Start

Page 18: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 18

User Enabled

Event Controller

JvmtiEnvThreadState

User Enabled

Enabled

Computed Enabled

JvmtiEventEnabled

JvmtiThreadState

Computed Enabled

JvmtiEnv

Computed Enabled

JvmtiEventController

Computed Enabled

JvmtiExport

Method enter/exit

Frame pops

interp_only_mode

User EnableSet CallbacksNew EnvSet Frame Pop

Thread-Start

Page 19: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 19

Generated Code: Originates from Spec

jvmti.xml

Page 20: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 20

Generated Code: Generated by XSL

jvmti.xml

jvmtiH.xsl

jvmtiHpp.xsl

jvmtiEnter.xsl

jvmdiEnter.xsl

jvmti.xsl

jvmtiEnv.xsl

JvmtiLib.xsl

Page 21: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 21

Generated Code: Interfaces, Code, Doc

jvmti.xml

jvmti.h

jvmtiEnv.hpp

jvmtiEnter.cpp

jvmdiEnter.cpp

jvmtiEnvStub.cpp

jvmti.html

jvmtiH.xsl

jvmtiHpp.xsl

jvmtiEnter.xsl

jvmdiEnter.xsl

jvmti.xsl

jvmtiEnv.xsl

JvmtiLib.xsl

Page 22: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 22

Generated Code: Stubs filled

jvmti.xml

jvmti.h

jvmtiEnv.hpp

jvmtiEnter.cpp

jvmdiEnter.cpp

jvmtiEnvStub.cpp

jvmti.html

jvmtiEnv.cpp

jvmtiEnvRecommended.cpp

jvmtiH.xsl

jvmtiHpp.xsl

jvmtiEnter.xsl

jvmdiEnter.xsl

jvmti.xsl

jvmtiEnv.xsl

jvmtiEnvFill.java

JvmtiLib.xsl

copy/edit

Page 23: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 23

jvmtiRedefineClasses.cpp

• Implemented as VM_Operation• Used by both RedefineClasses and

RetransformClasses• Dan Daugherty owns this now• Rocket science• See doc in jvmtiRedefineClasses.hpp

Page 24: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 24

jvmtiClassFileReconstituter.cpp

• Retransformation uses the redefinition code• But first, HotSpot data structures must be

converted to a class file

Page 25: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 25

jvmtiTagMap.cpp

• Implements heap functionality (heap iteration and walks)

• JVM TI heap functionality identifies objects by user supplied tags

• jvmtiTagMap.cpp maps oops to JNI weak ref and tag

Page 26: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 26

jvmtiManageCapabilities.cpp

• Checks availability of requested capabilities

• Merges with other environments• Converts capabilities to JvmtiExport flags

JvmtiExport::set_can_post_exceptions(

avail.can_generate_exception_events ||

avail.can_generate_frame_pop_events ||

avail.can_generate_method_exit_events);

Page 27: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 27

JVM TI – Implementation in HotSpot

Q & A

Page 28: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 28

Function Origins

New JVMTI: 27

From just JVMPI: 4Cloned

JVMPI discarded: 9

All three: 13

From JVMDI: 84 Morphed

(from just JVMDI: 71)

JVMTI (Total: 116)

JVMPI

JVM

DI

To Scale

Page 29: JVM Tool Interface (JVM TI) Implementation in HotSpotImplementation: Layers – JVM TI View •Transitions from JVM TI (external C interface) •To HotSpot implementation of JVM TI

Copyright 2007, Sun Microsystems, Inc 29

Event OriginsJVMTI (Total: 36)

JVM

DI

JVMPI

New JVMTI: 5

From just JVMPI: 14

Cloned

All three: 6

From JVMDI: 17 Morphed

(from just JVMDI: 11)JVMPI

discarded: 17

To Scale