FileDocCategorySizeDatePackage
SlotAllocator.javaAPI DocJava SE 6 API2654Tue Jun 10 00:22:32 BST 2008com.sun.org.apache.xalan.internal.xsltc.compiler.util

SlotAllocator

public final class SlotAllocator extends Object
author
Jacek Ambroziak

Fields Summary
private int
_firstAvailableSlot
private int
_size
private int
_free
private int[]
_slotsTaken
Constructors Summary
Methods Summary
public intallocateSlot(com.sun.org.apache.bcel.internal.generic.Type type)

	final int size = type.getSize();
	final int limit = _free;
	int slot = _firstAvailableSlot, where = 0;

	if (_free + size > _size) {
	    final int[] array = new int[_size *= 2];
	    for (int j = 0; j < limit; j++)
		array[j] = _slotsTaken[j];
	    _slotsTaken = array;
	}

	while (where < limit) {
	    if (slot + size <= _slotsTaken[where]) {
		// insert
		for (int j = limit - 1; j >= where; j--)
		    _slotsTaken[j + size] = _slotsTaken[j];
		break;
	    }
	    else {
		slot = _slotsTaken[where++] + 1;
	    }
	}
	
	for (int j = 0; j < size; j++)
	    _slotsTaken[where + j] = slot + j;
	
	_free += size;
	return slot;
    
public voidinitialize(com.sun.org.apache.bcel.internal.generic.LocalVariableGen[] vars)

    
        
	final int length = vars.length;
	int slot = 0, size, index;

	for (int i = 0; i < length; i++) {
	    size  = vars[i].getType().getSize();
	    index = vars[i].getIndex();
	    slot  = Math.max(slot, index + size);
	}
	_firstAvailableSlot = slot;
    
public voidreleaseSlot(com.sun.org.apache.bcel.internal.generic.LocalVariableGen lvg)

	final int size = lvg.getType().getSize();
	final int slot = lvg.getIndex();
	final int limit = _free;
	
	for (int i = 0; i < limit; i++) {
	    if (_slotsTaken[i] == slot) {
		int j = i + size;
		while (j < limit) {
		    _slotsTaken[i++] = _slotsTaken[j++];
		}
		_free -= size;
		return;
	    }
	}
	String state = "Variable slot allocation error"+
	               "(size="+size+", slot="+slot+", limit="+limit+")";
	ErrorMsg err = new ErrorMsg(ErrorMsg.INTERNAL_ERR, state);
	throw new Error(err.toString());