Methoden implementiert werden.
Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
+ Roman Obermaisser EMAIL: cacao@complang.tuwien.ac.at
+ Andreas Krall EMAIL: cacao@complang.tuwien.ac.at
Last Change: 1996/11/14
/* for java-string to char conversion */
#define MAXSTRINGSIZE 1000
-/******************** systemclasses required for native methods *****/
+/******************** systemclasses required for native methods ***************/
static classinfo *class_java_lang_Class;
static classinfo *class_java_lang_Cloneable;
/* for raising exceptions from native methods */
java_objectheader* exceptionptr = NULL;
-/************* use classinfo structure as java.lang.Class object *************/
+/************* use classinfo structure as java.lang.Class object **************/
static void use_class_as_object (classinfo *c)
{
c->header.vftbl = class_java_lang_Class -> vftbl;
}
-/*********************** include Java Native Interface ***********************/
+/*********************** include Java Native Interface ************************/
#include "jni.c"
-/*************************** include native methods **************************/
+/*************************** include native methods ***************************/
#include "nat/Object.c"
#include "nat/String.c"
#include "nat/ClassLoader_NativeLibrary.c"
#include "nat/UnixFileSystem.c"
-/************************** tables for methods *******************************/
+/************************** tables for methods ********************************/
/* table for locating native methods */
static struct nativeref {
static bool nativecompdone = false;
-/*********************** function: native_loadclasses ************************
+/*********************** function: native_loadclasses **************************
load classes required for native methods
-******************************************************************************/
+*******************************************************************************/
void native_loadclasses()
{
);
}
-/*************** adds a library to the vector of loaded libraries ************/
+/*************** adds a library to the vector of loaded libraries *************/
void systemclassloader_addlibrary(java_objectheader *o)
{
/* create object and call initializer */
SystemClassLoader = (java_lang_ClassLoader*) native_new_and_init(class_java_lang_ClassLoader);
+ heap_addreference((void**) &SystemClassLoader);
/* systemclassloader has no parent */
SystemClassLoader->parent = NULL;
}
-/********************* add loaded library name ******************************/
+/********************* add loaded library name *******************************/
void systemclassloader_addlibname(java_objectheader *o)
{
}
-/********************* function: native_setclasspath *************************/
+/********************* function: native_setclasspath **************************/
void native_setclasspath (char *path)
{
classpath = path;
}
-/***************** function: throw_classnotfoundexception ********************/
+/***************** function: throw_classnotfoundexception *********************/
void throw_classnotfoundexception()
{
}
-/*********************** Funktion: native_findfunction ************************
+/*********************** Funktion: native_findfunction *************************
Sucht in der Tabelle die passende Methode (muss mit Klassennamen,
Methodennamen, Descriptor und 'static'-Status "ubereinstimmen),
functionptr native_findfunction (utf *cname, utf *mname,
utf *desc, bool isstatic)
{
- u4 i;
+ int i;
/* entry of table for fast string comparison */
struct nativecompref *n;
/* for warning message if no function is found */
char *buffer;
- int buffer_len,pos;
+ int buffer_len, pos;
isstatic = isstatic ? true : false;
if (!nativecompdone) {
- for (i=0; i<NATIVETABLESIZE; i++) {
- nativecomptable[i].classname =
+ for (i = 0; i < NATIVETABLESIZE; i++) {
+ nativecomptable[i].classname =
utf_new_char(nativetable[i].classname);
- nativecomptable[i].methodname =
+ nativecomptable[i].methodname =
utf_new_char(nativetable[i].methodname);
- nativecomptable[i].descriptor =
+ nativecomptable[i].descriptor =
utf_new_char(nativetable[i].descriptor);
- nativecomptable[i].isstatic =
+ nativecomptable[i].isstatic =
nativetable[i].isstatic;
- nativecomptable[i].func =
+ nativecomptable[i].func =
nativetable[i].func;
}
nativecompdone = true;
}
- for (i=0; i<NATIVETABLESIZE; i++) {
+ for (i = 0; i < NATIVETABLESIZE; i++) {
n = &(nativecomptable[i]);
- if (cname==n->classname && mname==n->methodname &&
- desc==n->descriptor && isstatic==n->isstatic) return n->func;
+ if (cname == n->classname && mname == n->methodname &&
+ desc == n->descriptor && isstatic == n->isstatic)
+ return n->func;
}
/* no function was found, display warning */
buffer = MNEW(char, buffer_len);
- strcpy(buffer,"warning: native function ");
- utf_sprint(buffer+strlen(buffer),mname);
- strcpy(buffer+strlen(buffer),": ");
- utf_sprint(buffer+strlen(buffer),desc);
- strcpy(buffer+strlen(buffer)," not found in class ");
- utf_sprint(buffer+strlen(buffer),cname);
+ strcpy(buffer, "warning: native function ");
+ utf_sprint(buffer+strlen(buffer), mname);
+ strcpy(buffer+strlen(buffer), ": ");
+ utf_sprint(buffer+strlen(buffer), desc);
+ strcpy(buffer+strlen(buffer), " not found in class ");
+ utf_sprint(buffer+strlen(buffer), cname);
log_text(buffer);
- MFREE(buffer,char,buffer_len);
+ MFREE(buffer, char, buffer_len);
return NULL;
}
-/********************** function: javastring_new *****************************
+/********************** function: javastring_new *******************************
creates a new object of type java/lang/String with the text of
the specified utf8-string
-
- return: pointer to the string or NULL (no memory)
-*****************************************************************************/
+ return: pointer to the string or NULL if memory is exhausted.
+
+*******************************************************************************/
java_objectheader *javastring_new (utf *u)
{
- char *utf_ptr = u->text; /* pointer to current unicode character in utf string */
- u4 utflength = utf_strlen(u); /* length of utf-string if uncompressed */
- java_lang_String *s; /* result-string */
+ char *utf_ptr = u->text; /* current utf character in utf string */
+ int utflength = utf_strlen(u); /* length of utf-string if uncompressed */
+ java_lang_String *s; /* result-string */
java_chararray *a;
- u4 i;
+ s4 i;
s = (java_lang_String*) builtin_new (class_java_lang_String);
a = builtin_newarray_char (utflength);
/* javastring or character-array could not be created */
- if ( (!a) || (!s) ) return NULL;
+ if ((!a) || (!s))
+ return NULL;
/* decompress utf-string */
- for (i=0; i<utflength; i++) a->data[i] = utf_nextu2(&utf_ptr);
+ for (i = 0; i < utflength; i++)
+ a->data[i] = utf_nextu2(&utf_ptr);
/* set fields of the javastring-object */
s -> value = a;
return (java_objectheader*) s;
}
-/********************** Funktion: javastring_new_char ************************
+/********************** function: javastring_new_char **************************
- Legt ein neues Objekt vom Typ java/lang/String an, und tr"agt als Text
- den "ubergebenen C-String ein.
- Return: Zeiger auf den String, oder NULL (wenn Speicher aus)
+ creates a new java/lang/String object which contains the convertet
+ C-string passed via text.
-*****************************************************************************/
+ return: the object pointer or NULL if memory is exhausted.
+
+*******************************************************************************/
java_objectheader *javastring_new_char (char *text)
{
- u4 i;
- u4 len = strlen(text); /* length of the string */
+ s4 i;
+ s4 len = strlen(text); /* length of the string */
java_lang_String *s; /* result-string */
java_chararray *a;
a = builtin_newarray_char (len);
/* javastring or character-array could not be created */
- if ( (!a) || (!s) ) return NULL;
+ if ((!a) || (!s)) return NULL;
/* copy text */
- for (i=0; i<len; i++) a->data[i] = text[i];
+ for (i = 0; i < len; i++)
+ a->data[i] = text[i];
/* set fields of the javastring-object */
s -> value = a;
}
-/************************* Funktion: javastring_tochar *****************************
+/************************* function javastring_tochar **************************
- Macht aus einem java-string einen C-String, und liefert den Zeiger
- darauf zur"uck.
- Achtung: Beim n"achsten Aufruf der Funktion wird der vorige String
- "uberschrieben
+ converts a Java string into a C string.
+
+ return: pointer to C string
+
+ Caution: every call of this function overwrites the previous string !!!
-***********************************************************************************/
+*******************************************************************************/
-char stringbuffer[MAXSTRINGSIZE];
+static char stringbuffer[MAXSTRINGSIZE];
char *javastring_tochar (java_objectheader *so)
{
java_lang_String *s = (java_lang_String*) so;
java_chararray *a;
- u4 i;
+ s4 i;
- if (!s) return "";
+ if (!s)
+ return "";
a = s->value;
- if (!a) return "";
- if (s->count > MAXSTRINGSIZE) return "";
- for (i=0; i<s->count; i++) stringbuffer[i] = a->data[s->offset+i];
+ if (!a)
+ return "";
+ if (s->count > MAXSTRINGSIZE)
+ return "";
+ for (i = 0; i < s->count; i++)
+ stringbuffer[i] = a->data[s->offset+i];
stringbuffer[i] = '\0';
return stringbuffer;
}
-/****************** function class_findfield_approx ***************************
+
+/****************** function class_findfield_approx ****************************
searches in 'classinfo'-structure for a field with the
specified name
}
-/******************** Funktion: native_new_and_init *************************
+/********************** function: native_new_and_init *************************
- Legt ein neues Objekt einer Klasse am Heap an, und ruft automatisch
- die Initialisierungsmethode auf.
- Return: Der Zeiger auf das Objekt, oder NULL, wenn kein Speicher
- mehr frei ist.
+ Creates a new object on the heap and calls the initializer.
+ Returns the object pointer or NULL if memory is exhausted.
-*****************************************************************************/
+*******************************************************************************/
java_objectheader *native_new_and_init (classinfo *c)
{
methodinfo *m;
- java_objectheader *o = builtin_new (c); /* create object */
+ java_objectheader *o = builtin_new (c); /* create object */
if (!o) return NULL;
/* find initializer */
- m = class_findmethod (c,
- utf_new_char ("<init>"),
- utf_new_char ("()V"));
+
+ m = class_findmethod(c, utf_new_char("<init>"), utf_new_char("()V"));
- if (!m) {
- /* initializer not ofund */
- log_text ("warning: class has no instance-initializer:");
- utf_sprint (logtext, c->name);
+ if (!m) { /* initializer not found */
+ sprintf(logtext, "warning: class has no instance-initializer: ");
+ utf_sprint(logtext + strlen(logtext), c->name);
dolog();
return o;
}
/* call initializer */
- asm_calljavamethod (m, o,NULL,NULL,NULL);
+
+ asm_calljavamethod (m, o, NULL, NULL, NULL);
return o;
}
java_lang_String *js;
java_chararray *a;
literalstring *s; /* hashtable entry */
- u4 i;
+ int i;
- for (i=0; i<string_hash.size; i++) {
+ for (i = 0; i < string_hash.size; i++) {
s = string_hash.ptr[i];
if (s) {
while (s) {
js = (java_lang_String *) s->string;
if (!js || !(a = js->value))
- /* error in hashtable found */
- panic("invalid literalstring in hashtable");
+ /* error in hashtable found */
+ panic("invalid literalstring in hashtable");
if (!js->header.vftbl)
- /* vftbl of javastring is NULL */
- js->header.vftbl = class_java_lang_String -> vftbl;
+ /* vftbl of javastring is NULL */
+ js->header.vftbl = class_java_lang_String -> vftbl;
if (!a->header.objheader.vftbl)
- /* vftbl of character-array is NULL */
- a->header.objheader.vftbl = class_array -> vftbl;
+ /* vftbl of character-array is NULL */
+ a->header.objheader.vftbl = class_array -> vftbl;
/* follow link in external hash chain */
s = s->hashlink;
Methoden implementiert werden.
Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
+ Roman Obermaisser EMAIL: cacao@complang.tuwien.ac.at
+ Andreas Krall EMAIL: cacao@complang.tuwien.ac.at
Last Change: 1996/11/14
/* for java-string to char conversion */
#define MAXSTRINGSIZE 1000
-/******************** systemclasses required for native methods *****/
+/******************** systemclasses required for native methods ***************/
static classinfo *class_java_lang_Class;
static classinfo *class_java_lang_Cloneable;
/* for raising exceptions from native methods */
java_objectheader* exceptionptr = NULL;
-/************* use classinfo structure as java.lang.Class object *************/
+/************* use classinfo structure as java.lang.Class object **************/
static void use_class_as_object (classinfo *c)
{
c->header.vftbl = class_java_lang_Class -> vftbl;
}
-/*********************** include Java Native Interface ***********************/
+/*********************** include Java Native Interface ************************/
#include "jni.c"
-/*************************** include native methods **************************/
+/*************************** include native methods ***************************/
#include "nat/Object.c"
#include "nat/String.c"
#include "nat/ClassLoader_NativeLibrary.c"
#include "nat/UnixFileSystem.c"
-/************************** tables for methods *******************************/
+/************************** tables for methods ********************************/
/* table for locating native methods */
static struct nativeref {
static bool nativecompdone = false;
-/*********************** function: native_loadclasses ************************
+/*********************** function: native_loadclasses **************************
load classes required for native methods
-******************************************************************************/
+*******************************************************************************/
void native_loadclasses()
{
);
}
-/*************** adds a library to the vector of loaded libraries ************/
+/*************** adds a library to the vector of loaded libraries *************/
void systemclassloader_addlibrary(java_objectheader *o)
{
/* create object and call initializer */
SystemClassLoader = (java_lang_ClassLoader*) native_new_and_init(class_java_lang_ClassLoader);
+ heap_addreference((void**) &SystemClassLoader);
/* systemclassloader has no parent */
SystemClassLoader->parent = NULL;
}
-/********************* add loaded library name ******************************/
+/********************* add loaded library name *******************************/
void systemclassloader_addlibname(java_objectheader *o)
{
}
-/********************* function: native_setclasspath *************************/
+/********************* function: native_setclasspath **************************/
void native_setclasspath (char *path)
{
classpath = path;
}
-/***************** function: throw_classnotfoundexception ********************/
+/***************** function: throw_classnotfoundexception *********************/
void throw_classnotfoundexception()
{
}
-/*********************** Funktion: native_findfunction ************************
+/*********************** Funktion: native_findfunction *************************
Sucht in der Tabelle die passende Methode (muss mit Klassennamen,
Methodennamen, Descriptor und 'static'-Status "ubereinstimmen),
functionptr native_findfunction (utf *cname, utf *mname,
utf *desc, bool isstatic)
{
- u4 i;
+ int i;
/* entry of table for fast string comparison */
struct nativecompref *n;
/* for warning message if no function is found */
char *buffer;
- int buffer_len,pos;
+ int buffer_len, pos;
isstatic = isstatic ? true : false;
if (!nativecompdone) {
- for (i=0; i<NATIVETABLESIZE; i++) {
- nativecomptable[i].classname =
+ for (i = 0; i < NATIVETABLESIZE; i++) {
+ nativecomptable[i].classname =
utf_new_char(nativetable[i].classname);
- nativecomptable[i].methodname =
+ nativecomptable[i].methodname =
utf_new_char(nativetable[i].methodname);
- nativecomptable[i].descriptor =
+ nativecomptable[i].descriptor =
utf_new_char(nativetable[i].descriptor);
- nativecomptable[i].isstatic =
+ nativecomptable[i].isstatic =
nativetable[i].isstatic;
- nativecomptable[i].func =
+ nativecomptable[i].func =
nativetable[i].func;
}
nativecompdone = true;
}
- for (i=0; i<NATIVETABLESIZE; i++) {
+ for (i = 0; i < NATIVETABLESIZE; i++) {
n = &(nativecomptable[i]);
- if (cname==n->classname && mname==n->methodname &&
- desc==n->descriptor && isstatic==n->isstatic) return n->func;
+ if (cname == n->classname && mname == n->methodname &&
+ desc == n->descriptor && isstatic == n->isstatic)
+ return n->func;
}
/* no function was found, display warning */
buffer = MNEW(char, buffer_len);
- strcpy(buffer,"warning: native function ");
- utf_sprint(buffer+strlen(buffer),mname);
- strcpy(buffer+strlen(buffer),": ");
- utf_sprint(buffer+strlen(buffer),desc);
- strcpy(buffer+strlen(buffer)," not found in class ");
- utf_sprint(buffer+strlen(buffer),cname);
+ strcpy(buffer, "warning: native function ");
+ utf_sprint(buffer+strlen(buffer), mname);
+ strcpy(buffer+strlen(buffer), ": ");
+ utf_sprint(buffer+strlen(buffer), desc);
+ strcpy(buffer+strlen(buffer), " not found in class ");
+ utf_sprint(buffer+strlen(buffer), cname);
log_text(buffer);
- MFREE(buffer,char,buffer_len);
+ MFREE(buffer, char, buffer_len);
return NULL;
}
-/********************** function: javastring_new *****************************
+/********************** function: javastring_new *******************************
creates a new object of type java/lang/String with the text of
the specified utf8-string
-
- return: pointer to the string or NULL (no memory)
-*****************************************************************************/
+ return: pointer to the string or NULL if memory is exhausted.
+
+*******************************************************************************/
java_objectheader *javastring_new (utf *u)
{
- char *utf_ptr = u->text; /* pointer to current unicode character in utf string */
- u4 utflength = utf_strlen(u); /* length of utf-string if uncompressed */
- java_lang_String *s; /* result-string */
+ char *utf_ptr = u->text; /* current utf character in utf string */
+ int utflength = utf_strlen(u); /* length of utf-string if uncompressed */
+ java_lang_String *s; /* result-string */
java_chararray *a;
- u4 i;
+ s4 i;
s = (java_lang_String*) builtin_new (class_java_lang_String);
a = builtin_newarray_char (utflength);
/* javastring or character-array could not be created */
- if ( (!a) || (!s) ) return NULL;
+ if ((!a) || (!s))
+ return NULL;
/* decompress utf-string */
- for (i=0; i<utflength; i++) a->data[i] = utf_nextu2(&utf_ptr);
+ for (i = 0; i < utflength; i++)
+ a->data[i] = utf_nextu2(&utf_ptr);
/* set fields of the javastring-object */
s -> value = a;
return (java_objectheader*) s;
}
-/********************** Funktion: javastring_new_char ************************
+/********************** function: javastring_new_char **************************
- Legt ein neues Objekt vom Typ java/lang/String an, und tr"agt als Text
- den "ubergebenen C-String ein.
- Return: Zeiger auf den String, oder NULL (wenn Speicher aus)
+ creates a new java/lang/String object which contains the convertet
+ C-string passed via text.
-*****************************************************************************/
+ return: the object pointer or NULL if memory is exhausted.
+
+*******************************************************************************/
java_objectheader *javastring_new_char (char *text)
{
- u4 i;
- u4 len = strlen(text); /* length of the string */
+ s4 i;
+ s4 len = strlen(text); /* length of the string */
java_lang_String *s; /* result-string */
java_chararray *a;
a = builtin_newarray_char (len);
/* javastring or character-array could not be created */
- if ( (!a) || (!s) ) return NULL;
+ if ((!a) || (!s)) return NULL;
/* copy text */
- for (i=0; i<len; i++) a->data[i] = text[i];
+ for (i = 0; i < len; i++)
+ a->data[i] = text[i];
/* set fields of the javastring-object */
s -> value = a;
}
-/************************* Funktion: javastring_tochar *****************************
+/************************* function javastring_tochar **************************
- Macht aus einem java-string einen C-String, und liefert den Zeiger
- darauf zur"uck.
- Achtung: Beim n"achsten Aufruf der Funktion wird der vorige String
- "uberschrieben
+ converts a Java string into a C string.
+
+ return: pointer to C string
+
+ Caution: every call of this function overwrites the previous string !!!
-***********************************************************************************/
+*******************************************************************************/
-char stringbuffer[MAXSTRINGSIZE];
+static char stringbuffer[MAXSTRINGSIZE];
char *javastring_tochar (java_objectheader *so)
{
java_lang_String *s = (java_lang_String*) so;
java_chararray *a;
- u4 i;
+ s4 i;
- if (!s) return "";
+ if (!s)
+ return "";
a = s->value;
- if (!a) return "";
- if (s->count > MAXSTRINGSIZE) return "";
- for (i=0; i<s->count; i++) stringbuffer[i] = a->data[s->offset+i];
+ if (!a)
+ return "";
+ if (s->count > MAXSTRINGSIZE)
+ return "";
+ for (i = 0; i < s->count; i++)
+ stringbuffer[i] = a->data[s->offset+i];
stringbuffer[i] = '\0';
return stringbuffer;
}
-/****************** function class_findfield_approx ***************************
+
+/****************** function class_findfield_approx ****************************
searches in 'classinfo'-structure for a field with the
specified name
}
-/******************** Funktion: native_new_and_init *************************
+/********************** function: native_new_and_init *************************
- Legt ein neues Objekt einer Klasse am Heap an, und ruft automatisch
- die Initialisierungsmethode auf.
- Return: Der Zeiger auf das Objekt, oder NULL, wenn kein Speicher
- mehr frei ist.
+ Creates a new object on the heap and calls the initializer.
+ Returns the object pointer or NULL if memory is exhausted.
-*****************************************************************************/
+*******************************************************************************/
java_objectheader *native_new_and_init (classinfo *c)
{
methodinfo *m;
- java_objectheader *o = builtin_new (c); /* create object */
+ java_objectheader *o = builtin_new (c); /* create object */
if (!o) return NULL;
/* find initializer */
- m = class_findmethod (c,
- utf_new_char ("<init>"),
- utf_new_char ("()V"));
+
+ m = class_findmethod(c, utf_new_char("<init>"), utf_new_char("()V"));
- if (!m) {
- /* initializer not ofund */
- log_text ("warning: class has no instance-initializer:");
- utf_sprint (logtext, c->name);
+ if (!m) { /* initializer not found */
+ sprintf(logtext, "warning: class has no instance-initializer: ");
+ utf_sprint(logtext + strlen(logtext), c->name);
dolog();
return o;
}
/* call initializer */
- asm_calljavamethod (m, o,NULL,NULL,NULL);
+
+ asm_calljavamethod (m, o, NULL, NULL, NULL);
return o;
}
java_lang_String *js;
java_chararray *a;
literalstring *s; /* hashtable entry */
- u4 i;
+ int i;
- for (i=0; i<string_hash.size; i++) {
+ for (i = 0; i < string_hash.size; i++) {
s = string_hash.ptr[i];
if (s) {
while (s) {
js = (java_lang_String *) s->string;
if (!js || !(a = js->value))
- /* error in hashtable found */
- panic("invalid literalstring in hashtable");
+ /* error in hashtable found */
+ panic("invalid literalstring in hashtable");
if (!js->header.vftbl)
- /* vftbl of javastring is NULL */
- js->header.vftbl = class_java_lang_String -> vftbl;
+ /* vftbl of javastring is NULL */
+ js->header.vftbl = class_java_lang_String -> vftbl;
if (!a->header.objheader.vftbl)
- /* vftbl of character-array is NULL */
- a->header.objheader.vftbl = class_array -> vftbl;
+ /* vftbl of character-array is NULL */
+ a->header.objheader.vftbl = class_array -> vftbl;
/* follow link in external hash chain */
s = s->hashlink;