SlideShare una empresa de Scribd logo
1 de 53
Descargar para leer sin conexión
JVM byte code
class file format

Nick Bova
Sep 1 2013
About myself
• In IT since 2000
• 6 years with mainframes
• Refactoring FinExpert virtual machine and finex
programming language
• Many assemblers in institute
•
•
•
•
•

Skype – mykola_bova
Twitter – mykola_bova
Facebook - FB/myk.bova
LinkedIn – ua.linkedin.com/in/mykbova
E-mail – bova.mykola@gmail.com
Why JVM byte code?
• A key to JVM internals and Java itself
• Practical understanding –key
for solving difficult problems
• A way to understand how it “really” works
What will be / will not be here?
• JVM and JVM byte code (JVM spec)
• “Touch” JVM byte code on practice (reJ,
ClassEditor)

• Libraries for byte code manipulation? – No
• Am I JVM / JVM byte code expert? - No
The ClassFile Structure
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
The Constant Pool (1)
cp_info {
u1 tag;
u1 info[];
}
The Constant Pool (2)
• Table 4.3. Constant pool tags
Constant Type
CONSTANT_Class
CONSTANT_Fieldref
CONSTANT_Methodref
CONSTANT_InterfaceMethodref
CONSTANT_String
CONSTANT_Integer
CONSTANT_Float
CONSTANT_Long
CONSTANT_Double
CONSTANT_NameAndType
CONSTANT_Utf8
CONSTANT_MethodHandle
CONSTANT_MethodType
CONSTANT_InvokeDynamic

Value
7
9
10
11
8
3
4
5
6
12
1
15
16
18
The Constant Pool CONSTANT_Class_info
CONSTANT_Class_info {
u1 tag;
u2 name_index;
}
The CONSTANT_Class_info structure is used to
represent a class or an interface
The Constant Pool - CONSTANT_Fieldref_info,
CONSTANT_Methodref_info, and
CONSTANT_InterfaceMethodref_info
CONSTANT_Fieldref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
CONSTANT_Methodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
CONSTANT_InterfaceMethodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
Fields, methods, and interface methods are represented by similar structures
The Constant Pool - The CONSTANT_String_info
Structure

CONSTANT_String_info {
u1 tag;
u2 string_index;
}
The CONSTANT_String_info structure is used to
represent constant objects of the type String
The Constant Pool - CONSTANT_Integer_info and
CONSTANT_Float_info
CONSTANT_Integer_info {
u1 tag;
u4 bytes;
}
CONSTANT_Float_info {
u1 tag;
u4 bytes;
}
The CONSTANT_Integer_info and CONSTANT_Float_info
structures represent 4-byte numeric (int and float)
constants
The Constant Pool - The CONSTANT_Long_info and
CONSTANT_Double_info
CONSTANT_Long_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}
CONSTANT_Double_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}
The CONSTANT_Long_info and CONSTANT_Double_info
represent 8-byte numeric (long and double) constants
The Constant Pool - CONSTANT_NameAndType_info

CONSTANT_NameAndType_info {
u1 tag;
u2 name_index;
u2 descriptor_index;
}
The CONSTANT_NameAndType_info structure is
used to represent a field or method, without
indicating which class or interface type it belongs
to
The Constant Pool - CONSTANT_Utf8_info

CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes[length];
}
The CONSTANT_Utf8_info structure is used to
represent constant string values
The Constant Pool - CONSTANT_MethodHandle_info

CONSTANT_MethodHandle_info {
u1 tag;
u1 reference_kind;
u2 reference_index;
}
The CONSTANT_MethodHandle_info structure is
used to represent a method handle
The Constant Pool - CONSTANT_MethodType_info

CONSTANT_MethodType_info {
u1 tag;
u2 descriptor_index;
}
The CONSTANT_MethodType_info structure is
used to represent a method type
The Constant Pool - CONSTANT_InvokeDynamic_info

CONSTANT_InvokeDynamic_info {
u1 tag;
u2 bootstrap_method_attr_index;
u2 name_and_type_index;
}
The CONSTANT_InvokeDynamic_info structure is
used by an invokedynamic
instruction to specify a bootstrap method
The ClassFile Structure – Fields (1)

field_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
The ClassFile Structure – Fields (2) - Field access and
property flags
Flag Name
ACC_PUBLIC
ACC_PRIVATE
ACC_PROTECTED
ACC_STATIC
ACC_FINAL
ACC_VOLATILE
ACC_TRANSIENT
ACC_SYNTHETIC
source code.
ACC_ENUM

Value
0x0001
0x0002
0x0004
0x0008
0x0010
0x0040
0x0080
0x1000

Interpretation
Declared public.
Declared private.
Declared protected.
Declared static.
Declared final.
Declared volatile; cannot be cached.
Declared transient;
Declared synthetic; not present in the

0x4000

Declared as an element of an enum.
The ClassFile Structure – Methods (1)

method_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
The ClassFile Structure – Methods (2) – Methods
access and property flags
Flag Name
ACC_PUBLIC
ACC_PRIVATE
ACC_PROTECTED
ACC_STATIC
ACC_FINAL
ACC_SYNCHRONIZED
by a monitor use.
ACC_BRIDGE
ACC_VARARGS
ACC_NATIVE
than Java.
ACC_ABSTRACT
provided.
ACC_STRICT
ACC_SYNTHETIC

Value
0x0001
0x0002
0x0004
0x0008
0x0010
0x0020

Interpretation
Declared public.
Declared private.
Declared protected.
Declared static.
Declared final.
Declared synchronized; invocation is wrapped

0x0040
0x0080
0x0100

A bridge method, generated by the compiler.
Declared with variable number of arguments.
Declared native; implemented in a language other

0x0400

Declared abstract; no implementation is

0x0800
0x1000

Declared strictfp; floating-point mode is FPstrict.
Declared synthetic; not present in the source code.
The ClassFile Structure – Attributes (1)

attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
The ClassFile Structure – Attributes (2) - Predefined
class file attributes
Attribute
Java SE
ConstantValue
1.0.2
Code
1.0.2
StackMapTable
6
Exceptions
1.0.2
InnerClasses
1.1
EnclosingMethod
5.0
Synthetic
1.1
Signature
5.0
SourceFile
1.0.2
SourceDebugExtension
5.0
LineNumberTable
1.0.2
LocalVariableTable
1.0.2
LocalVariableTypeTable
5.0
Deprecated
1.1
RuntimeVisibleAnnotations
5.0
RuntimeInvisibleAnnotations
5.0
RuntimeVisibleParameterAnnotations 5.0
RuntimeInvisibleParameterAnnotations 5.0
AnnotationDefault
5.0
BootstrapMethods
7

class file
45.3
45.3
50.0
45.3
45.3
49.0
45.3
49.0
45.3
49.0
45.3
45.3
49.0
45.3
49.0
49.0
49.0
49.0
49.0
51.0
Predefined class file attributes (1) - ConstantValue

ConstantValue_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 constantvalue_index;
}
A ConstantValue attribute represents the value
of a constant field.
Predefined class file attributes (2) - Code
Code_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 max_stack;
u2 max_locals;
u4 code_length;
u1 code[code_length];
u2 exception_table_length;
{ u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
} exception_table[exception_table_length];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
Predefined class file attributes (3) - StackMapTable

StackMapTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_entries;
stack_map_frame entries[number_of_entries];
}
This attribute is used during the process of
verification by type checking
Predefined class file attributes (4) - Exceptions
Exceptions_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_exceptions;
u2 exception_index_table[number_of_exceptions];
}
The Exceptions attribute is a variable-length attribute in
the attributes table of a method_info structure. The
Exceptions attribute indicates which checked
exceptions. a method may throw.
Predefined class file attributes (5) - InnerClasses
InnerClasses_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_classes;
{ u2 inner_class_info_index;
u2 outer_class_info_index;
u2 inner_name_index;
u2 inner_class_access_flags;
} classes[number_of_classes];
}
.
Predefined class file attributes (6) - EnclosingMethod

EnclosingMethod_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 class_index;
u2 method_index;
} throw.
A class must have an EnclosingMethod attribute if
and only if it is a local class or an anonymous
class.
Predefined class file attributes (7) - Synthetic

Synthetic_attribute {
u2 attribute_name_index;
u4 attribute_length;
}
A class member that does not appear in the
source code must be marked using a Synthetic
attribute
Predefined class file attributes (8) - Signature

Signature_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 signature_index;
}
The Signature attribute records generic signature
information for any class whose generic signature
in the Java programming language would include
references to type variables or parameterized
types.
Predefined class file attributes (9) - SourceFile

SourceFile_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 sourcefile_index;
}
Predefined class file attributes (10) SourceDebugExtension

SourceDebugExtension_attribute {
u2 attribute_name_index;
u4 attribute_length;
u1 debug_extension[attribute_length];
}
Predefined class file attributes (11) - LineNumberTable
LineNumberTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 line_number_table_length;
{ u2 start_pc;
u2 line_number;
} line_number_table[line_number_table_length];
}
It may be used by debuggers to determine which part of
the Java Virtual Machine code array corresponds to a
given line number in the original source file.
Predefined class file attributes (12) LocalVariableTable
LocalVariableTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 local_variable_table_length;
{ u2 start_pc;
u2 length;
u2 name_index;
u2 descriptor_index;
u2 index;
} local_variable_table[local_variable_table_length];
}
It may be used by debuggers to determine the value of a given local
variable during the execution of a method.
Predefined class file attributes (13) LocalVariableTypeTable
LocalVariableTypeTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 local_variable_type_table_length;
{ u2 start_pc;
u2 length;
u2 name_index;
u2 signature_index;
u2 index;
} local_variable_type_table[local_variable_type_table_length];
}
It may be used by debuggers to determine the value of a given local
variable during the execution of a method.
Predefined class file attributes (14) - Deprecated

Deprecated_attribute {
u2 attribute_name_index;
u4 attribute_length;
}
A class, interface, method, or field may be
marked using a Deprecated attribute to
indicate that the class, interface, method, or
field has been superseded.
Predefined class file attributes (15) –
RuntimeVisibleAnnotations part 1

RuntimeVisibleAnnotations_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 num_annotations;
annotation annotations[num_annotations];
}
The RuntimeVisibleAnnotations attribute records
run-time-visible Java programming language
annotations on the corresponding class, field, or
method.
Predefined class file attributes (15) –
RuntimeVisibleAnnotations part 2

annotation {
u2 type_index;
u2 num_element_value_pairs;
{ u2 element_name_index;
element_value value;
}
element_value_pairs[num_element_value_pairs];
}
Predefined class file attributes (15) –
RuntimeVisibleAnnotations part 3
element_value {
u1 tag;
union {
u2 const_value_index;
{ u2 type_name_index;
u2 const_name_index;
} enum_const_value;
u2 class_info_index;
annotation annotation_value;
{ u2 num_values;
element_value values[num_values];
} array_value;
} value;
}
Predefined class file attributes (16) –
RuntimeInvisibleAnnotations

RuntimeInvisibleAnnotations_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 num_annotations;
annotation annotations[num_annotations];
}
Annotations represented by a
RuntimeInvisibleAnnotations attribute must not
be made available for return by reflective APIs
Predefined class file attributes (17) –
RuntimeVisibleParameterAnnotations
RuntimeVisibleParameterAnnotations_attribute {
u2 attribute_name_index;
u4 attribute_length;
u1 num_parameters;
{ u2 num_annotations;
annotation annotations[num_annotations];
} parameter_annotations[num_parameters];
}
The RuntimeVisibleParameterAnnotations attribute records
run-time-visible Java programming language annotations
on the parameters of the corresponding method.
Predefined class file attributes (18) –
RuntimeInvisibleParameterAnnotations

RuntimeInvisibleParameterAnnotations_attribute {
u2 attribute_name_index;
u4 attribute_length;
u1 num_parameters;
{ u2 num_annotations;
annotation annotations[num_annotations];
} parameter_annotations[num_parameters];
}
Predefined class file attributes (19) –
AnnotationDefault

AnnotationDefault_attribute {
u2 attribute_name_index;
u4 attribute_length;
element_value default_value;
}
The AnnotationDefault attribute records the
default value
Predefined class file attributes (20) –
BootstrapMethods
BootstrapMethods_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 num_bootstrap_methods;
{ u2 bootstrap_method_ref;
u2 num_bootstrap_arguments;
u2 bootstrap_arguments[num_bootstrap_arguments];
} bootstrap_methods[num_bootstrap_methods];
}
The BootstrapMethods attribute records bootstrap method
specifiers referenced by invokedynamic instructions
Class format

CA

FE

BA

BE

Minor version

Major version

Constant pool

Flags

This class
Interfaces
Fields
Methods

Attributes

Super class
Class format

CA

FE

BA

BE

Minor version

Major version

Constant pool

Flags

This class
Interfaces
Fields
Methods

Attributes

Super class
Class format

CA

FE

BA

BE

Minor version

Major version

Constant pool

Flags

This class
Interfaces
Fields
Methods

Attributes

Super class
Class format

CA

FE

BA

BE

Minor version

Major version

Constant pool

Flags

This class
Interfaces
Fields
Methods

Attributes

Super class
Class format

CA

FE

BA

BE

Minor version

Major version

Constant pool

Flags

This class
Interfaces
Fields
Methods

Attributes

Super class
Class format

CA

FE

BA

BE

Minor version

Major version

Constant pool

Flags

This class
Interfaces
Fields
Methods

Attributes

Super class
Class format

CA

FE

BA

BE

Minor version

Major version

Constant pool

Flags

This class
Interfaces
Fields
Methods

Attributes

Super class
Easy Hack with
Constant Pool

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Java interface
Java interfaceJava interface
Java interface
 
Class method
Class methodClass method
Class method
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Ppt chapter03
Ppt chapter03Ppt chapter03
Ppt chapter03
 
C# Types of classes
C# Types of classesC# Types of classes
C# Types of classes
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Java interface
Java interfaceJava interface
Java interface
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
Unit v(dsc++)
Unit v(dsc++)Unit v(dsc++)
Unit v(dsc++)
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 

Similar a Jvm1 (20)

SOEN6441.generics.ppt
SOEN6441.generics.pptSOEN6441.generics.ppt
SOEN6441.generics.ppt
 
LectureNotes-02-DSA
LectureNotes-02-DSALectureNotes-02-DSA
LectureNotes-02-DSA
 
core_java.ppt
core_java.pptcore_java.ppt
core_java.ppt
 
L04 base patterns
L04 base patternsL04 base patterns
L04 base patterns
 
Chapter3 bag2
Chapter3 bag2Chapter3 bag2
Chapter3 bag2
 
springdatajpa-up.pdf
springdatajpa-up.pdfspringdatajpa-up.pdf
springdatajpa-up.pdf
 
Reflection Slides by Zubair Dar
Reflection Slides by Zubair DarReflection Slides by Zubair Dar
Reflection Slides by Zubair Dar
 
Java Annotations
Java AnnotationsJava Annotations
Java Annotations
 
Unit3 packages & interfaces
Unit3 packages & interfacesUnit3 packages & interfaces
Unit3 packages & interfaces
 
Love Twig
Love TwigLove Twig
Love Twig
 
Variables and Data Types
Variables and Data TypesVariables and Data Types
Variables and Data Types
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
 
Maf3 - Part 1
Maf3 - Part 1Maf3 - Part 1
Maf3 - Part 1
 
Writing Galaxy Tools
Writing Galaxy ToolsWriting Galaxy Tools
Writing Galaxy Tools
 
C Sharp Course 101.5
C Sharp Course 101.5C Sharp Course 101.5
C Sharp Course 101.5
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Understanding Annotations in Java
Understanding Annotations in JavaUnderstanding Annotations in Java
Understanding Annotations in Java
 
JVM and OOPS Introduction
JVM and OOPS IntroductionJVM and OOPS Introduction
JVM and OOPS Introduction
 

Más de Mykola Bova

backbase-cxp-datasheet
backbase-cxp-datasheetbackbase-cxp-datasheet
backbase-cxp-datasheetMykola Bova
 
inside dvm internals
inside dvm internalsinside dvm internals
inside dvm internalsMykola Bova
 
Inside Dvm tools
Inside Dvm toolsInside Dvm tools
Inside Dvm toolsMykola Bova
 
Inside Dvm basics
Inside Dvm basicsInside Dvm basics
Inside Dvm basicsMykola Bova
 
Dvm internals intro
Dvm internals introDvm internals intro
Dvm internals introMykola Bova
 

Más de Mykola Bova (6)

backbase-cxp-datasheet
backbase-cxp-datasheetbackbase-cxp-datasheet
backbase-cxp-datasheet
 
inside dvm internals
inside dvm internalsinside dvm internals
inside dvm internals
 
Inside Dvm tools
Inside Dvm toolsInside Dvm tools
Inside Dvm tools
 
Inside Dvm basics
Inside Dvm basicsInside Dvm basics
Inside Dvm basics
 
Dvm internals intro
Dvm internals introDvm internals intro
Dvm internals intro
 
Jvm2
Jvm2Jvm2
Jvm2
 

Último

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 

Último (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 

Jvm1

  • 1. JVM byte code class file format Nick Bova Sep 1 2013
  • 2. About myself • In IT since 2000 • 6 years with mainframes • Refactoring FinExpert virtual machine and finex programming language • Many assemblers in institute • • • • • Skype – mykola_bova Twitter – mykola_bova Facebook - FB/myk.bova LinkedIn – ua.linkedin.com/in/mykbova E-mail – bova.mykola@gmail.com
  • 3. Why JVM byte code? • A key to JVM internals and Java itself • Practical understanding –key for solving difficult problems • A way to understand how it “really” works
  • 4. What will be / will not be here? • JVM and JVM byte code (JVM spec) • “Touch” JVM byte code on practice (reJ, ClassEditor) • Libraries for byte code manipulation? – No • Am I JVM / JVM byte code expert? - No
  • 5. The ClassFile Structure ClassFile { u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[constant_pool_count-1]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[interfaces_count]; u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; }
  • 6. The Constant Pool (1) cp_info { u1 tag; u1 info[]; }
  • 7. The Constant Pool (2) • Table 4.3. Constant pool tags Constant Type CONSTANT_Class CONSTANT_Fieldref CONSTANT_Methodref CONSTANT_InterfaceMethodref CONSTANT_String CONSTANT_Integer CONSTANT_Float CONSTANT_Long CONSTANT_Double CONSTANT_NameAndType CONSTANT_Utf8 CONSTANT_MethodHandle CONSTANT_MethodType CONSTANT_InvokeDynamic Value 7 9 10 11 8 3 4 5 6 12 1 15 16 18
  • 8. The Constant Pool CONSTANT_Class_info CONSTANT_Class_info { u1 tag; u2 name_index; } The CONSTANT_Class_info structure is used to represent a class or an interface
  • 9. The Constant Pool - CONSTANT_Fieldref_info, CONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info CONSTANT_Fieldref_info { u1 tag; u2 class_index; u2 name_and_type_index; } CONSTANT_Methodref_info { u1 tag; u2 class_index; u2 name_and_type_index; } CONSTANT_InterfaceMethodref_info { u1 tag; u2 class_index; u2 name_and_type_index; } Fields, methods, and interface methods are represented by similar structures
  • 10. The Constant Pool - The CONSTANT_String_info Structure CONSTANT_String_info { u1 tag; u2 string_index; } The CONSTANT_String_info structure is used to represent constant objects of the type String
  • 11. The Constant Pool - CONSTANT_Integer_info and CONSTANT_Float_info CONSTANT_Integer_info { u1 tag; u4 bytes; } CONSTANT_Float_info { u1 tag; u4 bytes; } The CONSTANT_Integer_info and CONSTANT_Float_info structures represent 4-byte numeric (int and float) constants
  • 12. The Constant Pool - The CONSTANT_Long_info and CONSTANT_Double_info CONSTANT_Long_info { u1 tag; u4 high_bytes; u4 low_bytes; } CONSTANT_Double_info { u1 tag; u4 high_bytes; u4 low_bytes; } The CONSTANT_Long_info and CONSTANT_Double_info represent 8-byte numeric (long and double) constants
  • 13. The Constant Pool - CONSTANT_NameAndType_info CONSTANT_NameAndType_info { u1 tag; u2 name_index; u2 descriptor_index; } The CONSTANT_NameAndType_info structure is used to represent a field or method, without indicating which class or interface type it belongs to
  • 14. The Constant Pool - CONSTANT_Utf8_info CONSTANT_Utf8_info { u1 tag; u2 length; u1 bytes[length]; } The CONSTANT_Utf8_info structure is used to represent constant string values
  • 15. The Constant Pool - CONSTANT_MethodHandle_info CONSTANT_MethodHandle_info { u1 tag; u1 reference_kind; u2 reference_index; } The CONSTANT_MethodHandle_info structure is used to represent a method handle
  • 16. The Constant Pool - CONSTANT_MethodType_info CONSTANT_MethodType_info { u1 tag; u2 descriptor_index; } The CONSTANT_MethodType_info structure is used to represent a method type
  • 17. The Constant Pool - CONSTANT_InvokeDynamic_info CONSTANT_InvokeDynamic_info { u1 tag; u2 bootstrap_method_attr_index; u2 name_and_type_index; } The CONSTANT_InvokeDynamic_info structure is used by an invokedynamic instruction to specify a bootstrap method
  • 18. The ClassFile Structure – Fields (1) field_info { u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info attributes[attributes_count]; }
  • 19. The ClassFile Structure – Fields (2) - Field access and property flags Flag Name ACC_PUBLIC ACC_PRIVATE ACC_PROTECTED ACC_STATIC ACC_FINAL ACC_VOLATILE ACC_TRANSIENT ACC_SYNTHETIC source code. ACC_ENUM Value 0x0001 0x0002 0x0004 0x0008 0x0010 0x0040 0x0080 0x1000 Interpretation Declared public. Declared private. Declared protected. Declared static. Declared final. Declared volatile; cannot be cached. Declared transient; Declared synthetic; not present in the 0x4000 Declared as an element of an enum.
  • 20. The ClassFile Structure – Methods (1) method_info { u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info attributes[attributes_count]; }
  • 21. The ClassFile Structure – Methods (2) – Methods access and property flags Flag Name ACC_PUBLIC ACC_PRIVATE ACC_PROTECTED ACC_STATIC ACC_FINAL ACC_SYNCHRONIZED by a monitor use. ACC_BRIDGE ACC_VARARGS ACC_NATIVE than Java. ACC_ABSTRACT provided. ACC_STRICT ACC_SYNTHETIC Value 0x0001 0x0002 0x0004 0x0008 0x0010 0x0020 Interpretation Declared public. Declared private. Declared protected. Declared static. Declared final. Declared synchronized; invocation is wrapped 0x0040 0x0080 0x0100 A bridge method, generated by the compiler. Declared with variable number of arguments. Declared native; implemented in a language other 0x0400 Declared abstract; no implementation is 0x0800 0x1000 Declared strictfp; floating-point mode is FPstrict. Declared synthetic; not present in the source code.
  • 22. The ClassFile Structure – Attributes (1) attribute_info { u2 attribute_name_index; u4 attribute_length; u1 info[attribute_length]; }
  • 23. The ClassFile Structure – Attributes (2) - Predefined class file attributes Attribute Java SE ConstantValue 1.0.2 Code 1.0.2 StackMapTable 6 Exceptions 1.0.2 InnerClasses 1.1 EnclosingMethod 5.0 Synthetic 1.1 Signature 5.0 SourceFile 1.0.2 SourceDebugExtension 5.0 LineNumberTable 1.0.2 LocalVariableTable 1.0.2 LocalVariableTypeTable 5.0 Deprecated 1.1 RuntimeVisibleAnnotations 5.0 RuntimeInvisibleAnnotations 5.0 RuntimeVisibleParameterAnnotations 5.0 RuntimeInvisibleParameterAnnotations 5.0 AnnotationDefault 5.0 BootstrapMethods 7 class file 45.3 45.3 50.0 45.3 45.3 49.0 45.3 49.0 45.3 49.0 45.3 45.3 49.0 45.3 49.0 49.0 49.0 49.0 49.0 51.0
  • 24. Predefined class file attributes (1) - ConstantValue ConstantValue_attribute { u2 attribute_name_index; u4 attribute_length; u2 constantvalue_index; } A ConstantValue attribute represents the value of a constant field.
  • 25. Predefined class file attributes (2) - Code Code_attribute { u2 attribute_name_index; u4 attribute_length; u2 max_stack; u2 max_locals; u4 code_length; u1 code[code_length]; u2 exception_table_length; { u2 start_pc; u2 end_pc; u2 handler_pc; u2 catch_type; } exception_table[exception_table_length]; u2 attributes_count; attribute_info attributes[attributes_count]; }
  • 26. Predefined class file attributes (3) - StackMapTable StackMapTable_attribute { u2 attribute_name_index; u4 attribute_length; u2 number_of_entries; stack_map_frame entries[number_of_entries]; } This attribute is used during the process of verification by type checking
  • 27. Predefined class file attributes (4) - Exceptions Exceptions_attribute { u2 attribute_name_index; u4 attribute_length; u2 number_of_exceptions; u2 exception_index_table[number_of_exceptions]; } The Exceptions attribute is a variable-length attribute in the attributes table of a method_info structure. The Exceptions attribute indicates which checked exceptions. a method may throw.
  • 28. Predefined class file attributes (5) - InnerClasses InnerClasses_attribute { u2 attribute_name_index; u4 attribute_length; u2 number_of_classes; { u2 inner_class_info_index; u2 outer_class_info_index; u2 inner_name_index; u2 inner_class_access_flags; } classes[number_of_classes]; } .
  • 29. Predefined class file attributes (6) - EnclosingMethod EnclosingMethod_attribute { u2 attribute_name_index; u4 attribute_length; u2 class_index; u2 method_index; } throw. A class must have an EnclosingMethod attribute if and only if it is a local class or an anonymous class.
  • 30. Predefined class file attributes (7) - Synthetic Synthetic_attribute { u2 attribute_name_index; u4 attribute_length; } A class member that does not appear in the source code must be marked using a Synthetic attribute
  • 31. Predefined class file attributes (8) - Signature Signature_attribute { u2 attribute_name_index; u4 attribute_length; u2 signature_index; } The Signature attribute records generic signature information for any class whose generic signature in the Java programming language would include references to type variables or parameterized types.
  • 32. Predefined class file attributes (9) - SourceFile SourceFile_attribute { u2 attribute_name_index; u4 attribute_length; u2 sourcefile_index; }
  • 33. Predefined class file attributes (10) SourceDebugExtension SourceDebugExtension_attribute { u2 attribute_name_index; u4 attribute_length; u1 debug_extension[attribute_length]; }
  • 34. Predefined class file attributes (11) - LineNumberTable LineNumberTable_attribute { u2 attribute_name_index; u4 attribute_length; u2 line_number_table_length; { u2 start_pc; u2 line_number; } line_number_table[line_number_table_length]; } It may be used by debuggers to determine which part of the Java Virtual Machine code array corresponds to a given line number in the original source file.
  • 35. Predefined class file attributes (12) LocalVariableTable LocalVariableTable_attribute { u2 attribute_name_index; u4 attribute_length; u2 local_variable_table_length; { u2 start_pc; u2 length; u2 name_index; u2 descriptor_index; u2 index; } local_variable_table[local_variable_table_length]; } It may be used by debuggers to determine the value of a given local variable during the execution of a method.
  • 36. Predefined class file attributes (13) LocalVariableTypeTable LocalVariableTypeTable_attribute { u2 attribute_name_index; u4 attribute_length; u2 local_variable_type_table_length; { u2 start_pc; u2 length; u2 name_index; u2 signature_index; u2 index; } local_variable_type_table[local_variable_type_table_length]; } It may be used by debuggers to determine the value of a given local variable during the execution of a method.
  • 37. Predefined class file attributes (14) - Deprecated Deprecated_attribute { u2 attribute_name_index; u4 attribute_length; } A class, interface, method, or field may be marked using a Deprecated attribute to indicate that the class, interface, method, or field has been superseded.
  • 38. Predefined class file attributes (15) – RuntimeVisibleAnnotations part 1 RuntimeVisibleAnnotations_attribute { u2 attribute_name_index; u4 attribute_length; u2 num_annotations; annotation annotations[num_annotations]; } The RuntimeVisibleAnnotations attribute records run-time-visible Java programming language annotations on the corresponding class, field, or method.
  • 39. Predefined class file attributes (15) – RuntimeVisibleAnnotations part 2 annotation { u2 type_index; u2 num_element_value_pairs; { u2 element_name_index; element_value value; } element_value_pairs[num_element_value_pairs]; }
  • 40. Predefined class file attributes (15) – RuntimeVisibleAnnotations part 3 element_value { u1 tag; union { u2 const_value_index; { u2 type_name_index; u2 const_name_index; } enum_const_value; u2 class_info_index; annotation annotation_value; { u2 num_values; element_value values[num_values]; } array_value; } value; }
  • 41. Predefined class file attributes (16) – RuntimeInvisibleAnnotations RuntimeInvisibleAnnotations_attribute { u2 attribute_name_index; u4 attribute_length; u2 num_annotations; annotation annotations[num_annotations]; } Annotations represented by a RuntimeInvisibleAnnotations attribute must not be made available for return by reflective APIs
  • 42. Predefined class file attributes (17) – RuntimeVisibleParameterAnnotations RuntimeVisibleParameterAnnotations_attribute { u2 attribute_name_index; u4 attribute_length; u1 num_parameters; { u2 num_annotations; annotation annotations[num_annotations]; } parameter_annotations[num_parameters]; } The RuntimeVisibleParameterAnnotations attribute records run-time-visible Java programming language annotations on the parameters of the corresponding method.
  • 43. Predefined class file attributes (18) – RuntimeInvisibleParameterAnnotations RuntimeInvisibleParameterAnnotations_attribute { u2 attribute_name_index; u4 attribute_length; u1 num_parameters; { u2 num_annotations; annotation annotations[num_annotations]; } parameter_annotations[num_parameters]; }
  • 44. Predefined class file attributes (19) – AnnotationDefault AnnotationDefault_attribute { u2 attribute_name_index; u4 attribute_length; element_value default_value; } The AnnotationDefault attribute records the default value
  • 45. Predefined class file attributes (20) – BootstrapMethods BootstrapMethods_attribute { u2 attribute_name_index; u4 attribute_length; u2 num_bootstrap_methods; { u2 bootstrap_method_ref; u2 num_bootstrap_arguments; u2 bootstrap_arguments[num_bootstrap_arguments]; } bootstrap_methods[num_bootstrap_methods]; } The BootstrapMethods attribute records bootstrap method specifiers referenced by invokedynamic instructions
  • 46. Class format CA FE BA BE Minor version Major version Constant pool Flags This class Interfaces Fields Methods Attributes Super class
  • 47. Class format CA FE BA BE Minor version Major version Constant pool Flags This class Interfaces Fields Methods Attributes Super class
  • 48. Class format CA FE BA BE Minor version Major version Constant pool Flags This class Interfaces Fields Methods Attributes Super class
  • 49. Class format CA FE BA BE Minor version Major version Constant pool Flags This class Interfaces Fields Methods Attributes Super class
  • 50. Class format CA FE BA BE Minor version Major version Constant pool Flags This class Interfaces Fields Methods Attributes Super class
  • 51. Class format CA FE BA BE Minor version Major version Constant pool Flags This class Interfaces Fields Methods Attributes Super class
  • 52. Class format CA FE BA BE Minor version Major version Constant pool Flags This class Interfaces Fields Methods Attributes Super class