home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek Gadgets 1
/
ADE-1.bin
/
ade-dist
/
kaffe-0.5p4-src.tgz
/
tar.out
/
contrib
/
kaffe
/
kaffevm
/
baseClasses.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-28
|
5KB
|
248 lines
/*
* baseClasses.c
* Handle base classes.
*
* Copyright (c) 1996 Systems Architecture Research Centre,
* City University, London, UK.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
*/
#define DBG(s)
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#if defined(HAVE_MALLOC_H)
#include <malloc.h>
#endif
#include "gtypes.h"
#include "access.h"
#include "object.h"
#include "constants.h"
#include "classMethod.h"
#include "baseClasses.h"
#include "lookup.h"
#include "slots.h"
#include "external.h"
#include "machine.h"
#include "md.h"
char* ObjectClassName;
strpair* initpair;
strpair* finalpair;
classes* StringClass;
classes* ClassClass;
classes* ObjectClass;
classes* CloneableClass;
classes* CharArrayClass;
classes* classInitHead;
int classInitLevel = 2;
#define INIT "<clinit>"
#define INITSIG "()V"
#define FINAL "finalize"
#define FINALSIG "()V"
/* Initialisation prototypes */
void initClasspath(void);
void initExceptions(void);
void initNative(void);
void initThreads(void);
void initTypes(void);
/*
* Initialise the machine.
*/
void
initialise(void)
{
/* Setup garbage collection system */
initGc();
/* Setup CLASSPATH */
initClasspath();
/* Create the initialise launch pair */
initpair = addStringPair(INIT, INITSIG);
/* Create the finalize launch pair */
finalpair = addStringPair(FINAL, FINALSIG);
/* Read in base classes */
initBaseClasses();
/* Setup exceptions */
initExceptions();
/* Init native support */
initNative();
/* Init thread support */
initThreads();
}
/*
* We need to use certain classes in the internal machine so we better
* get them in now in a known way so we can refer back to them.
* Currently we need java/lang/Object, java/lang/Class and java/lang/String.
*/
void
initBaseClasses(void)
{
/* Start with the simple types. */
initTypes();
/* Read in object */
ObjectClassName = addString(OBJECTCLASS);
ObjectClass = lookupClass(ObjectClassName);
if (ObjectClass == 0) {
fprintf(stderr, "Failed to find class %s ... aborting.\n", OBJECTCLASS);
exit(1);
}
/* Read in class */
ClassClass = lookupClass(addString(CLASSCLASS));
if (ClassClass == 0) {
fprintf(stderr, "Failed to find class %s ... aborting.\n", CLASSCLASS);
exit(1);
}
/* Fixup mtable because it couldn't be made for the first classes */
ClassClass->head.dtable = ClassClass->dtable;
ObjectClass->head.dtable = ClassClass->dtable;
/* Read in strings */
StringClass = lookupClass(addString(STRINGCLASS));
if (StringClass == 0) {
fprintf(stderr, "Failed to find class %s ... aborting.\n", STRINGCLASS);
exit(1);
}
/* Read in clonable class */
CloneableClass = lookupClass(addString(CLONEABLECLASS));
if (CloneableClass == 0) {
fprintf(stderr, "Failed to find class %s ... aborting.\n", CLONEABLECLASS);
exit(1);
}
/* Create char array class */
CharArrayClass = lookupArray("[C");
if (CharArrayClass == 0) {
fprintf(stderr, "Failed to find class %s ... aborting.\n", "[C");
exit(1);
}
initClasses();
}
/*
* Creata a string in the string cache.
*/
char*
addStringLen(char* s, int len)
{
strconst* m;
m = malloc(sizeof(strconst) + len + 1);
strncpy(m->data, s, len);
m->data[len] = 0;
return (addStringConstant(m));
}
/*
* Create a string pair in the string pair cache.
*/
strpair*
addStringPair(char* s1, char* s2)
{
strpair* pair;
pair = addStringConstantPair(addString(s1), addString(s2));
assert(pair != 0);
return (pair);
}
/*
* We translate a CONSTANT_Chararray to a CONSTANT_String on demand.
* The strings in the .class file are not held as real objects, so
* we convert them here.
*/
slots*
makeStringObject(int idx, constants* pool)
{
stringClass* obj;
assert(pool->tags[idx] == CONSTANT_Chararray);
obj = getString(STRING_DATA2BASE(pool->data[STRING_NAME(idx, pool)].v.tstr));
/* Install new object */
pool->tags[idx] = CONSTANT_String;
pool->data[idx].v.taddr = obj;
return (&pool->data[idx]);
}
/*
* Convert a strconst to a String object.
*/
stringClass*
getString(strconst* str)
{
stringClass* obj;
if (str->string == 0) {
obj = (stringClass*)alloc_object(StringClass, true);
assert(obj != 0);
obj->value = &str->obj;
obj->offset = 0; /* ??? */
obj->count = obj->value->size; /* ??? */
str->string = obj;
}
return (str->string);
}
/*
* Initialise classes.
*/
void
initClasses(void)
{
classes* class;
classes* nclass;
methods* meth;
classInitLevel++;
class = classInitHead;
classInitHead = 0;
while (class != 0) {
class->state = CSTATE_OK;
meth = findMethod(class, initpair);
assert(meth != 0);
DBG( printf("Initialising %s static %d\n", class->name, class->sfsize); fflush(stdout); )
CALL_KAFFE_FUNCTION(meth, 0);
nclass = class->nextInit;
class->nextInit = 0;
class->prevInit = 0;
class = nclass;
}
classInitLevel--;
/* We should never drop below our initial level of two */
assert(classInitLevel >= 2);
}