org.vishia.java2C
Class Docu.G_Instantiation

java.lang.Object
  extended by org.vishia.java2C.Docu.G_Instantiation
Enclosing class:
Docu

 class Docu.G_Instantiation
extends java.lang.Object

This chapter describes some cohesion of allocation, initializing (construction), finalizing, garbage collection.


Constructor Summary
Docu.G_Instantiation()
           
 
Method Summary
(package private)  void g1_kindOfInstances()
          In Java there are two kinds of instances: Primitive types such as int, float.
(package private)  void g10_enhancedRefs()
           
(package private)  void g11_garbageCollection()
           
(package private)  void g12_blockHeap()
           
(package private)  void g16_finalizing()
          Java knows a method Object.finalize(), which is called from the system before the instance is removed from memory.
(package private)  void g2_allocation()
           
(package private)  void g3_referencingWithMemC()
          In the CRuntimeJavalike context a struct MemC {int32 size_; MemAreaC* address;} is defined.
(package private)  void g5_ctor()
          The four kinds of instances (see g1_kindOfInstances()) uses several kinds of constructors to initial them with given arguments: Primitive types doesn't need a constructor.
(package private)  void g7_embeddedTypes()
          Embedded types are types, which are deployed in C with a simple small struct, handled call and return per value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Docu.G_Instantiation

Docu.G_Instantiation()
Method Detail

g1_kindOfInstances

void g1_kindOfInstances()
In Java there are two kinds of instances: In opposite, in C there are given four kinds of instances: Embedded types are types, which are deployed in C with a simple small struct, handled call and return per value. There are applications for that concept for special cases. * FieldData.modeAccess = '$'


g2_allocation

void g2_allocation()

g3_referencingWithMemC

void g3_referencingWithMemC()
In the CRuntimeJavalike context a struct MemC {int32 size_; MemAreaC* address;} is defined. It is placed in the header file fw_MemC.h, because it is not a own concept of CRuntimeJavalike, but an own concept of common C-programming. This struct MemC is an answer about the question: I have a void*-pointer to the memory, but which and how many bytes.... In generally a void*-pointer is a undefined thing. No type is given, no size is known. A void* is a well concept in the C-language with its closure to machine level, but not for user-level programming.

An instance described with MemC is undefined in type, but defined in size. It is a representation of raw memory. An allocation of memory with alloc_MemC(size) returns this struct with the found address and the associated size. It is one parameter for using. Otherwise the size is separated from the void*-pointer and mistakes are possible. The MemC comprises only 2 register values. Therefore most of C compilers return it in machine level in 2 register, not in a copied struct. It is efficient.


g5_ctor

void g5_ctor()
The four kinds of instances (see g1_kindOfInstances()) uses several kinds of constructors to initial them with given arguments:

g10_enhancedRefs

void g10_enhancedRefs()

g11_garbageCollection

void g11_garbageCollection()

g12_blockHeap

void g12_blockHeap()

g16_finalizing

void g16_finalizing()
Java knows a method Object.finalize(), which is called from the system before the instance is removed from memory. It is invoked in cohesion with the garbage collector. The finalize()- method can be overridden in any instance. But this method should be used carefully. It is not deterministic when and whether at all this method is invoked because the garbage- collector has its own rules. If the instance isn't use anymore, it is possible that it isn't removed by the garbage collector, because there is enough memory and thereby no need of freeing memory. A programmer shouldn't use this method for normal clearing up actions for example to close files.

In the case of using the #g5_blockHeap() the finalize method is used especially to remove enhanced references. The references may refer other instances which were in use, although the instance itself isn't use and it is freed therefore. The referred instances contains backward references to the freed instance. If the enhanced references are not cleaned, that backward references are faulty.

Therefore the finalize-method is generated from the Java2C-translator to clean the enhanced references. In the finalize()-method the finalized-methods of embedded instances and of the super classes are called too. If a user-written finalize()-method is present in the Java-code, its content will be included firstly.

Only for instances which aren't base on Object (simple data) and which doesn't contain enhanced references no finalize method is generated. The property ClassData.bFinalizeNeed contains the information about. It is set calling ClassData.needFinalize() or ClassData.setBodyForFinalize(org.vishia.zbnf.ZbnfParseResultItem). It is able to quest calling ClassData.isFinalizeNeed().

The finalize()-method is generated with SecondPass.write_finalizeDefinition(org.vishia.zbnf.ZbnfParseResultItem, String, LocalIdents).


g7_embeddedTypes

void g7_embeddedTypes()
Embedded types are types, which are deployed in C with a simple small struct, handled call and return per value. There are applications for that concept for special cases. * FieldData.modeAccess = '$'