[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The libjit
library does not implement a particular object model
of its own, so that it is generic across bytecode formats and front end
languages. However, it does provide support for plugging object models
into the JIT process, and for transparently proxying to external libraries
that may use a foreign object model.
There may be more than one object model active in the system at any one time. For example, a JVM implementation might have a primary object model for its own use, and a secondary object model for calling methods in an imported Objective C library.
The functions in this section support pluggable object models. There is
no requirement that you use them: you can ignore them and use the rest
of libjit
directly if you wish.
To create a new object model, you would include the file
<jit/jit-objmodel-private.h>
and create an instance of
the struct jit_objmodel
type. This instance should be
populated with pointers to your object model’s handler routines.
You then use functions from the list below to access the
object model.
Some standard object models are distributed with libjit
for invoking methods in external C++, Objective C, GCJ, and JNI
based libraries.
Destroy an object model handler that is no longer required. It is undefined what will happen to the objects and classes that were being managed by the object model: they may still persist, or they may now be invalid.
Get the class descriptor from the object model for a class
called name. Returns NULL if the class was not found.
If the name includes namespace or nested scope qualifiers,
they must be separated by periods (.
).
Get the name of a particular class. The return value must be freed
with jit_free
.
Get the access modifiers for a particular class. The following lists all access modifiers, for classes, fields and methods:
JITOM_MODIFIER_ACCESS_MASK
Mask to strip out just the public, private, etc access flags.
JITOM_MODIFIER_PUBLIC
JITOM_MODIFIER_PRIVATE
JITOM_MODIFIER_PROTECTED
JITOM_MODIFIER_PACKAGE
JITOM_MODIFIER_PACKAGE_OR_PROTECTED
JITOM_MODIFIER_PACKAGE_AND_PROTECTED
JITOM_MODIFIER_OTHER1
JITOM_MODIFIER_OTHER2
The declared access level on the class, field, or method. The scope of a "package" will typically be model-specific: Java uses namespaces to define packages, whereas C# uses compile units ("assemblies").
Object model handlers do not need to enforce the above access levels.
It is assumed that any caller with access to libjit
has complete
access to the entire system, and will use its own rules for determining
when it is appropriate to grant access to fields and methods.
JITOM_MODIFIER_STATIC
The field or method is static, rather than instance-based.
JITOM_MODIFIER_VIRTUAL
The method is instance-based and virtual.
JITOM_MODIFIER_NEW_SLOT
The method is virtual, but occupies a new slot. Provided for languages like C# that can declare virtual methods with the same name as in a superclass, but within a new slot in the vtable.
JITOM_MODIFIER_ABSTRACT
When used on a class, this indicates that the class contains abstract
methods. When used on a method, this indicates that the method does
not have any associated code in its defining class. It is not possible
to invoke such a method with jitom_method_invoke
, only
jitom_method_invoke_virtual
.
JITOM_MODIFIER_LITERAL
A hint flag, used on fields, to indicate that the field has a constant
value associated with it and does not occupy any real space. If the
jitom_field_load
function is used on such a field, it will load
the constant value.
JITOM_MODIFIER_CTOR
A hint flag that indicates that the method is an instance constructor.
JITOM_MODIFIER_STATIC_CTOR
A hint flag that indicates that the method is a static constructor. The object model handler is normally responsible for outputting calls to static constructors; the caller shouldn’t need to perform any special handling.
JITOM_MODIFIER_DTOR
A hint flag that indicates that the method is an instance destructor.
The class should also have the JITOM_MODIFIER_DELETE
flag.
Note: do not use this for object models that support automatic
garbage collection and finalization.
JITOM_MODIFIER_INTERFACE
The class is an interface.
JITOM_MODIFIER_VALUE
Instances of this class can be stored inline on the stack.
JITOM_MODIFIER_FINAL
When used on a class, this indicates that it cannot be subclassed. When used on a virtual method, this indicates that it cannot be overridden in subclasses.
JITOM_MODIFIER_DELETE
When used on a class, this indicates that its objects must be explicitly deleted when no longer required.
JITOM_MODIFIER_REFERENCE_COUNTED
When used on a class, this indicates that its objects are
reference-counted. Calling jitom_class_delete
will
reduce the reference count and delete the object for real
when the count reaches zero.
Get the JIT type descriptor that represents pointer-based
object references to a class. The object model handler should
use jitom_type_tag_as_class
to tag the return value.
The caller should use jit_type_free
to free the returned
value when it is no longer required.
Get the JIT type descriptor that represents inline stack instances
of the class. The object model handler should use
jitom_type_tag_as_value
to tag the return value.
The caller should use jit_type_free
to free the returned
value when it is no longer required.
Get the primary superclass for klass. If the object model supports
true multiple inheritance, then this should return the first superclass.
Note: for the purposes of this function, interfaces are not considered
superclasses. Use jitom_class_get_interfaces
instead.
Return an array of all superclasses for klass, with the number of
elements returned in num. Returns NULL if out of memory.
Use jit_free
to free the return array.
Return an array of all interfaces for klass, with the number
of elements returned in num. The list does not include interfaces
that are declared on superclasses. Returns NULL if out of memory.
Use jit_free
to free the return array.
Return an array of all fields for klass, with the number
of elements returned in num. The list does not include fields
that are declared on superclasses. Returns NULL if out of memory.
Use jit_free
to free the return array.
Return an array of all methods for klass, with the number
of elements returned in num. The list does not include methods
that are declared on superclasses. Returns NULL if out of memory.
Use jit_free
to free the return array.
Add instructions to func to create a new instance of the
specified class. If ctor is not NULL, then it indicates a
constructor that should be invoked with the arguments in args.
If ctor is NULL, then memory should be allocated, but no
constructor should be invoked. Returns a JIT value representing
the newly allocated object. The type of the value will be the same
as the the result from jitom_class_get_type
.
Add instructions to func to create a new instance of the
specified class, inline on the stack. If ctor is not NULL, then
it indicates a constructor that should be invoked with the arguments
in args. If ctor is NULL, then stack space should be
allocated, but no constructor should be invoked. Returns a JIT
value representing the newly allocated stack space. The type of the
value will be the same as the the result from
jitom_class_get_value_type
.
Delete an instance of a particular class, calling the destructor if
necessary. The obj_value may be an inline stack value,
in which case the destructor is called, but the memory is not freed.
Ignored if the class does not have the JITOM_MODIFIER_DELETE
modifier.
Note: no attempt is made to destroy inline stack values automatically when they go out of scope. It is up to the caller to output instructions in the appropriate places to do this.
Add a reference to a reference-counted object. Ignored if the
class does not have the JITOM_MODIFIER_REFERENCE_COUNTED
modifier,
or the value is stored inline on the stack.
Other functions, such as jitom_field_store
, may also change the
reference count, but such behavior is object model specific.
Get the name of a particular object model field. The return value must
be freed with jit_free
.
Get the type of a particular object model field.
Get the access modifiers that are associated with a particular object model field.
Create instructions within func to effect a load from a field within the object obj_value. If obj_value is NULL, then it indicates a static field reference.
If the field has the JITOM_MODIFIER_LITERAL
modifier, then this
function will load the constant value associated with the field.
Literal fields cannot be stored to.
Create instructions within func to get the address of a field within the object obj_value. If obj_value is NULL, then it indicates that we want the address of a static field. Some object models may not support this function, and will return NULL.
Create instructions within func to store value into a field within the object obj_value. If obj_value is NULL, then it indicates a static field store.
Get the name of an object model method. The return value must
be freed with jit_free
.
Get the signature type of an object model method. If the method
is instance-based, then the first argument will be an object reference
type indicating the this
pointer.
Get the access modifiers for an object model method.
Create instructions within func to invoke a static or
instance method. If an instance method is virtual, then this will
ignore the virtual property to invoke the designated method directly.
The first element in args should be the this
pointer
for instance methods.
Create instructions within func to invoke a virtual or interface
method. The first element in args should be the this
pointer for the call.
Tag a JIT type as an object reference belonging to a specific class. Returns NULL if there is insufficient memory to tag the type.
Tag a JIT type as an inline static value belonging to a specific class. Returns NULL if there is insufficient memory to tag the type.
Determine if a type is tagged as an object reference.
Determine if a type is tagged as an inline static value.
Get the object model associated with a type that was tagged with
jitom_type_tag_as_class
or jitom_type_tag_as_value
.
Get the class associated with a type that was tagged with
jitom_type_tag_as_class
or jitom_type_tag_as_value
.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on September 17, 2016 using texi2html 5.0.