Ejemplo n.º 1
0
/*
 * Initiate slots.
 */
void
initSlots(int nrslots)
{
	int i;
	static int lastnrslots = 0;

	/* Allocate extra slots for temps */
	nrslots += MAXTEMPS;

	/* Make sure we have enough slots space */
	if (nrslots > lastnrslots) {
		basicslots = KREALLOC(basicslots, nrslots * sizeof(SlotInfo));
		addToCounter(&jitmem, "jitmem-temp", 1,
			(nrslots - lastnrslots) * sizeof(SlotInfo));
		lastnrslots = nrslots;
	}
	/* Set 'maxslot' to the maximum slot usable (excluding returns) */
	maxslot = nrslots;

        /* Free all slots */
        for (i = 0; i < nrslots; i++) {
		basicslots[i].regno = NOREG;
		basicslots[i].modified = 0;
        }

	/* Setup various slot pointers */
	slotinfo = &basicslots[0];
	localinfo = NULL;
	tempinfo = NULL;
}
Ejemplo n.º 2
0
/*
 * Lookup an entry for a given (name, loader) pair.
 * Create one if none is found.
 */
classEntry*
lookupClassEntry(Utf8Const* name, Hjava_lang_ClassLoader* loader,
		 errorInfo *einfo)
{
	classEntry* entry;
	classEntry** entryp;
	static int f = 0;

        if (f == 0) {
		f++;
		registerUserCounter(&classStats, "class-pool", statClassPool);
        }

	entry = lookupClassEntryInternal(name, loader);
	if (entry != 0)
		return (entry);

	/* Failed to find class entry - create a new one */
	entry = gc_malloc(sizeof(classEntry), KGC_ALLOC_CLASSPOOL);
	if (entry == 0) {
		postOutOfMemory(einfo);
		return (NULL);
	}
	entry->name = name;
	entry->loader = loader;
	entry->data.cl = NULL;
	entry->next = NULL;
	initStaticLock(&entry->slock);

	/* Lock the class table and insert entry into it (if not already
	   there) */
        lockStaticMutex(&classHashLock);

	entryp = &classEntryPool[utf8ConstHashValue(name) & (CLASSHASHSZ-1)];
	for (; *entryp != 0; entryp = &(*entryp)->next) {
		if (utf8ConstEqual(name, (*entryp)->name) && loader == (*entryp)->loader) {
			/* Someone else added it - discard ours and return
			   the new one. */
			unlockStaticMutex(&classHashLock);
			KFREE(entry);
			return (*entryp);
		}
	}

	/* Add ours to end of hash */
	*entryp = entry;
	addToCounter(&cpemem, "vmmem-class entry pool", 1, GCSIZEOF(entry));

	/*
	 * This reference to the utf8 name will be released if and when this
	 * class entry is freed in destroyClassLoader.
	 */
	utf8ConstAddRef(entry->name);

        unlockStaticMutex(&classHashLock);

	return (entry);
}
Ejemplo n.º 3
0
/*
 * Remove all entries from the class entry pool that belong to a given
 * class.  Return the number of entries removed.
 */
int
removeClassEntries(Hjava_lang_ClassLoader* loader)
{
	classEntry** entryp;
	classEntry* entry;
	int ipool;
	int totalent = 0;

        lockStaticMutex(&classHashLock);
	for (ipool = CLASSHASHSZ;  --ipool >= 0; ) {
		entryp = &classEntryPool[ipool];
		while (*entryp != NULL) {
			/* loop invariant: entryp points at the next non-null
			 * entry that must be examined.
			 */
			entry = *entryp;
			if (entry->loader == loader) {
				/*
				 * If class gc is turned off, no classloader
				 * should ever be finalized because they're all
				 * kept alive by their respective classes.
				 */
				assert(entry->data.cl == 0 ||
					Kaffe_JavaVMArgs.enableClassGC != 0);
DBG(CLASSGC,
				dprintf("removing %s l=%p/c=%p\n",
				    entry->name->data, loader, entry->data.cl);
    );
				/* release reference to name */
				utf8ConstRelease(entry->name);
				(*entryp) = entry->next;
				addToCounter(&cpemem, "vmmem-class entry pool",
					1, -(jlong)GCSIZEOF(entry));
				destroyStaticLock(&entry->slock);
				gc_free(entry);
				totalent++;
			} else {
Ejemplo n.º 4
0
/*
 * Allocate a new label.
 */
label*
KaffeJIT_newLabel(void)
{
    int i;
    label* ret = currLabel;

    if (ret == 0) {
        /* Allocate chunk of label elements */
        ret = KCALLOC(ALLOCLABELNR, sizeof(label));
        addToCounter(&jitmem, "jitmem-temp", 1,
                     ALLOCLABELNR * sizeof(label));

        /* Attach to current chain */
        if (lastLabel == 0) {
            firstLabel = ret;
        }
        else {
            lastLabel->next = ret;
        }
        lastLabel = &ret[ALLOCLABELNR-1];

        /* Link elements into list */
        for (i = 0; i < ALLOCLABELNR-1; i++) {
#if defined(KAFFE_VMDEBUG)
            sprintf(ret[i].name, "L%d", labelCount + i);
#endif

            ret[i].next = &ret[i+1];
        }
        ret[ALLOCLABELNR-1].next = NULL;
    }
    currLabel = ret->next;
#if defined(KAFFE_VMDEBUG)
    labelCount += 1;
#endif
    return (ret);
}