• Keine Ergebnisse gefunden

JAVA - KLASSENDATEIEN

N/A
N/A
Protected

Academic year: 2022

Aktie "JAVA - KLASSENDATEIEN"

Copied!
29
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

JAVA - KLASSENDATEIEN

Seminarvortrag von

Studierach Beatrix

(2)

Überblick

 Klassendatei

 Spezielle Strings

 Constant Pool

 Attribute

(3)

Class-File

Programm in Java Programm

in anderer Sprache Programm

in Java

Compiler Compiler

Compiler

Java class

files Java class

files Other binary

format

(4)

Typen

1. PRIMITIVE TYPEN:

 u1 ...1 unsigned byte

 u2 ... 2 unsigned bytes

 u4 ... 4 unsigned bytes

 u8 ... 8 unsigned bytes 2. TABELLENNAME

Big Endian

(5)

Klassendatei - Struktur

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;

attributte_info attributes[attributes_count];

Magic Number: 0xCAFEBABE

(6)

Beispiele zur Version

 JDK 1.0.2 unterstützt Klassendatei- Formate der Versionen 45.0 bis 45.3

 SDK 1.2 unterstützt Klassendatei- Formate der Versionen 45.0 bis 46.0

Versionsnummer: 45.3

Major version no. Minor version no.

(7)

Klassendatei - Struktur

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;

attributte_info attributes[attributes_count];

(8)

Constant Pool

Tag: CONSTANT_Class name_index: 7

Tag: CONSTANT_Utf8_info length: 3

This_class: 1 bytes: „Act“

constant_pool Entry #1

constant_pool Entry #7

this class

(9)

Klassendatei - Struktur

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];

(10)

Access_flags

Flag Name Bedeutung Verwendung

ACC_PUBLIC Zugriff ausserhalb des

Package möglich Klasse, Interface

ACC_FINAL Keine Unterklassen

erlaubt Klasse

ACC_SUPER Hat geerbte Methoden Klasse, Interface

ACC_INTERFACE Ist ein Interface Interface

ACC_ABSTRACT Ist Abstract und kann nicht

instanziert werden Klasse, Interface

(11)

Überblick

 Klassendatei

 Spezielle Strings

 Constant Pool

 Attribute

(12)

Spezielle Strings

 Fully qualified Names

 Simple Names

 Descriptors

(13)

Fully qualified names

 Source Code:

– java.lang.Thread

 Class File:

– java/lang/Thread

(14)

Simple names

 Constant Pool Eintrag der auf die Methode String toString() verweist:

– „toString“

 Constant Pool Eintrag der auf das Feld java.io.PrintStram out verweist:

– „out“

(15)

Descriptors

FieldDescriptor:

FieldType ComponentType:

FieldType FieldType:

BaseType ObjectType ArrayType BaseType:

B C D F I J S Z

ObjectType:

L<classname>

ArrayType:

[ ComponentType MethodDesciptor:

( ParameterDesciptor * ) ReturnDesciptor ObjectType

ArrayType ParameterDesciptor:

FieldType ReturnDesciptor:

FieldType V

(16)

Beispiele - Field Desciptor

int i;  I

long [][] windingRoad;  [[J

java.lang.Object[] stuff  [Ljava/lang/Object

(17)

Beispiel – MethodDescriptor

 int getSize;

 ()I

 void main(String [] args);

 ([Ljava/lang/String;)V

 boolean regionMatches(boolean ignoreCase, int toOffset, String other, int offset, int len);

 (ZILjava/lang/Srting;II)Z

(18)

Überblick

 Klassendatei

 Spezielle Strings

 Constant Pool

 Attribute

(19)

Constant Pool

– Allgemeines Format

cp_ info { u1 tag;

u1 info[];

}

tag – Indikator für Typ des Eintrags

info – Inhalt variert mit Wert des Tags

(20)

Constant Pool - Tag

CONSTANT_Class

CONSTANT_Fieldref

CONSTANT_Methodref

CONSTANT_InterfaceMethodref

CONSTANT_String

CONSTANT_Integer

CONSTANT_Float

CONSTANT_Long

CONSTANT_Double

CONSTANT_NameAndType

CONSTANT_Utf8

(21)

Constant_Class

CONSTANT_Class_info{

U1 tag;

U2 name_index;

}

(22)

CONSTANT_NameAndType

CONSTANT_NameAndType_info{

U1 tag;

U2 name_index;

U2 desciptor_index;

}

(23)

CONSTANT_UTF8

CONSTANT_utf8_info{

U1 tag;

U2 length;

U2 bytes[length];

}

(24)

Überblick

 Klassendatei

 Spezielle Strings

 Constant Pool

 Attribute

(25)

Attribute

Code

ConstantValue

Deprecated

Exceptions

InnerClasses

LineNumberTable

LocalVariableTable

SourceFile

Synthetic

(26)

ConstantValue

ConstantValue_attribute {

u2 attribute_name_index;

u4 attribute_length;

u2 constantvalue_index;

}

(27)

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]:

}

(28)

LocalVariableTable

LocalVariableTable _attribute {

u2 attribute_name_index;

u4 attribute_length;

u2 local_variable_table_length;

{ u2 start_pc;

u2 length;

u2 name_index;

u2 name_index;

u2 descriptor_index;

u2 index;

} local_variable_table[local_variable_table_length]:

}

(29)

Danke für Ihre Aufmerksamkeit!

Referenzen

ÄHNLICHE DOKUMENTE

UV‐Licht Nein Prototyping EEPROM

UV‐Licht Nein Prototyping EEPROM

September 2017, dass zwei Jugendliche die Rutsche auf dem Spielplatz in der Karlsbader Straße mit Farbe besprühen.. Der hinzugezogene Kommunale Vollzugsdienst der Stadt (KVD) trafen

Optimismus, Begriff, unter dem in der Literatur verschiedene Konstrukte subsumiert werden. 1) 

Verhaltensänderung. Beispielsweise kann ein solches Modell zu der Vorhersage gelangen, daß 

Zusammenhang: Die relativ geringe mittlere Effektstärke von Z = 5.19 verweist darauf, daß 

• Für jede Klasse gibt es eine Methode String toString(), die eine String-Darstellung liefert. • Der Konkatenations-Operator “ +” ist mithilfe der Methode append() der

Benchmarking wird zunehmend auch für den Bildungsbereich gefordert.In- ternationale oder regionale Vergleiche ermöglichen eine Srärken-Schwächen- Analyse von Bildungssystemen..