Class Loading Flashcards

1
Q

Binary class format

A

Format:

  • init header `cafebabe’ to identify actual classes vs other binaries
  • major/minor version numbers
  • count of entries in constant pool
  • actual constant pool data
  • Superclass/interfaces - these reference constant pool entries for the class itself
  • Information about fields/methods (themselves complex structures)
  • Executable code for methods; code attributes contained within method definitions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Constant pool data

A

Stores all constants used by the class definition

  • class and method names, signatures, strings
  • Items of variable length: first byte=>type/how to decode
  • References to other methods and classes used by this class + declarations for this class and its method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Attributes

A

Some container for data

e. g. method bytecode, constants, value of a constant field
- JVM ignores attributes of unknown type - flexibility for extending use of attributes to serve other purposes [metadata for frameworks that work with user classes - C#]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

JVM

A
  • stack architecture

- operands: immediate or from constant pool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

JVM implementation

A
  • Interpreted: slower than executive native code
  • JIT translation: compile before executing the first time: better performance for repeated executions
  • Adaptive techniques to monitor program execution, selectively optimise heavily used code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Linking process in C

A

C => machine code

linking merges code from separately compiled source files + shared library code to form an executable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Linking in Java

A
  • no change to bytecode until loaded into JVM
  • linking performed by JVM when class is loaded into memory
  • some overhead as classes are initially loaded
  • flexibility: e.g.applications can be written to use interfaces with the actual implementations left unspecified until run time [late binding]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Loading classes in Java - when

A
  • only load when needed (but JVM has some flexibility, but must maintain a fixed sequence of class initialisation
  • dependencies between classes => recursive loading
  • Initial core classes used by even empty Java programs
  • Load dependencies only when an instance of the class is about to be created by code / static initialisers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Loading classes in Java - what happens

A
  • Decode binary class format
  • Check compatibility with other classes
  • Verify sequence of bytecode operations
  • Construct java.lang.Class instance to represent new class
  • Class instance becomes basis for all instances of the new class created by the JVM
  • Class object is the identifier for the loaded class itself – can have multiple copies of the same binary class loaded into the JVM each with its own Class instance - they share the same class name but will be separate classes to the JVM.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Bootstrap class loader

A
- built into JVM, responsible for loading basic Java class libraries 
special features:
- only load classes found on the boot class path
- less validation since these are trusted system classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Extension class loader

A

CL for loading classes from standard Java extension APIs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

System class loader

A

for loading classes from the general class path including your application classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Application defined class loaders - why

A
Runtime reloading of classes 
Derived from java.lang.ClassLoader provides core support for building an internal class representation from an array of bytes
Each constructed class is owned by the class loader that loaded it ... they keep a map from name => Class instance, for all loaded classes,  to be able to find one by name if it's requested again
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Class loader tree

A
1- class loader keeps reference to a parent class loader, defining a tree of class loaders with the bootstrap loader at the root.
2- When an instance of a particular class (identified by name)
is needed, whichever class loader initially handles the request normally checks with its parent class loader first before trying to load the class directly. 
3- This applies recursively if there are multiple layers of class loaders, so it means that a class will normally be visible not only within the class loader that loaded it, but also to all descendant class loaders. 
4- It also means that if a class can be loaded by more than one class loader in a chain, the one furthest up the tree will be the one that actually loads it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Example: utility of multiple class loaders, J2EE framework

A
  • each J2EE application loaded by the framework needs to have a separate class loader to prevent classes in one application from interfering with other applications
  • framework’s code itself will also use one or more other class loaders, to prevent interference to or from applications
  • complete set of classloaders make upa
How well did you know this?
1
Not at all
2
3
4
5
Perfectly