示例#1
0
void 
AddBinClass(ClassClass * cb)
{
    register int left, right, middle, result, i;
    char *name = cbName(cb);
    struct Hjava_lang_ClassLoader *loader = cbLoader(cb);
    
    BINCLASS_LOCK();
    left = 0;
    right = nbinclasses - 1;
    result = 1;
    while (left <= right) {
        ClassClass *cb1;
	middle = (left+right)/2;
	cb1 = binclasses[middle];
	result = strcmp(name, cbName(cb1));
	if (result == 0) {
	    if (loader < cbLoader(cb1)) {
	        result = -1;
	    } else if (loader > cbLoader(cb1)) {
	        result = 1;
	    } else {
	        result = 0;
	    }
	}
	if (result < 0) {
	    right = middle-1;
	} else if (result > 0) {
	    left = middle+1;
	} else {
	    break;
	}
    }
    if (result != 0) {
        if (nbinclasses >= sizebinclasses) {
	    if (binclasses == 0)
		binclasses = (ClassClass **)
		    sysMalloc(sizeof(ClassClass *) * (sizebinclasses = 50));
	    else
		binclasses = (ClassClass **)
		    sysRealloc(binclasses, sizeof(ClassClass *)
			    * (sizebinclasses = nbinclasses * 2));
	}
	if (binclasses == 0)
	    goto unlock;
	right++;
	for (i = nbinclasses; i > right; i--) {
	    binclasses[i] = binclasses[i-1];
	}
	binclasses[right] = cb;
	nbinclasses++;
    }

unlock:
    BINCLASS_UNLOCK();
}	
示例#2
0
char *
stat_source(ClassClass *cb, struct stat *s, char *pathbuf, int maxlen)
{
#define NAMEBUFLEN 255
    char nm[NAMEBUFLEN];
    char *p, *q, *lp;
    cpe_t **cpp;

    /* don't bother searching if absolute */
    /* REMIND: only here for compatibility */
    if (sysIsAbsolute(cbSourceName(cb))) {
	if (sysStat(cbSourceName(cb), s) == 0) {
	    if (jio_snprintf(pathbuf, maxlen, "%s", cbSourceName(cb)) == -1) {
		return 0;
	    }
	    return pathbuf;
	} else {
	    return 0;
	}
    }

    /* parse the package name */
    p = cbName(cb);
    if (strlen(p) > NAMEBUFLEN - 1) {
	return 0;
    }
    for (q = lp = nm ; *p ; p++) {
	if (*p == DIR_SEPARATOR) {
	    *q++ = LOCAL_DIR_SEPARATOR;
	    lp = q;
	} else {
	    *q++ = *p;
	}
    }

    /* append the source file name */
    p = cbSourceName(cb);
    if (strlen(p) + (lp - nm) > NAMEBUFLEN - 1) {
	return 0;
    }
    for (; *p ; p++) {
	*lp++ = (*p == DIR_SEPARATOR ? LOCAL_DIR_SEPARATOR : *p);
    }
    *lp = '\0';

    /* search the class path */
    for (cpp = sysGetClassPath() ; cpp && *cpp != 0 ; cpp++) {
	cpe_t *cpe = *cpp;
	if (cpe->type == CPE_DIR) {
	    if (jio_snprintf(pathbuf, maxlen, "%s%c%s",
			 cpe->u.dir, LOCAL_DIR_SEPARATOR, nm) == -1) {
		return 0;
	    }
	    if (sysStat(pathbuf, s) == 0) {
		return pathbuf;
	    }
	}
    }
    return 0;
}
示例#3
0
static char *getAscizFromClass(CICcontext *context, int value) 
{
    ClassClass *cb = context->cb;
    union cp_item_type *constant_pool = cbConstantPool(cb);
    int nconstants = cbConstantPoolCount(cb);
    unsigned char *type_table = 
	constant_pool[CONSTANT_POOL_TYPE_TABLE_INDEX].type;
    if ((value > 0) && (value < nconstants)) {
	if (type_table[value] == CONSTANT_Class) {
	    value = constant_pool[value].i;
	    if ((value <= 0) || (value >= nconstants) ||
		(type_table[value] != (CONSTANT_Utf8 |
				       CONSTANT_POOL_ENTRY_RESOLVED)))
		JAVA_ERROR(context, "Illegal constant pool index");
	    return constant_pool[value].cp;
	} else if (type_table[value] == (CONSTANT_Class |
		                         CONSTANT_POOL_ENTRY_RESOLVED)) {
	    ClassClass *cb = constant_pool[value].clazz;
	    return cbName(cb);
	} else {
	    JAVA_ERROR(context, "Illegal constant pool index");
	}
    } else {
	JAVA_ERROR(context, "Illegal constant pool index");
    }
    return NULL; /* not reached */
}
示例#4
0
char *GetClassConstantClassName(cp_item_type *constant_pool, int index)
{
    unsigned char *type_table = 
	constant_pool[CONSTANT_POOL_TYPE_TABLE_INDEX].type;
    switch(type_table[index]) {
        case CONSTANT_Class | CONSTANT_POOL_ENTRY_RESOLVED: {
	    ClassClass *cb = constant_pool[index].clazz;
	    return cbName(cb);
	}

        case CONSTANT_Class: {
	    int name_index = constant_pool[index].i;
	    return constant_pool[name_index].cp;
	}
	    
	default:
	    return (char *)0;
    }
}
示例#5
0
BOOL TestRunnerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	CListCtrl   *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
	CComboBox   *comboBox = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);

	ASSERT (listCtrl);
	ASSERT (comboBox);

	CString title;
	GetWindowText(title);
#if defined(_DEBUG)
	title.Append(" [debug]");
#else
	title.Append(" [release]");
#endif
	SetWindowText(title);

	listCtrl->InsertColumn (0,"Type", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("Type"), 1);
	listCtrl->InsertColumn (1,"Name", LVCFMT_LEFT, 16 * listCtrl->GetStringWidth ("X"), 2);
	listCtrl->InsertColumn (2,"Failed Condition", LVCFMT_LEFT, 24 * listCtrl->GetStringWidth ("M"), 3);
	listCtrl->InsertColumn (3,"Line", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("0000"), 4);
	listCtrl->InsertColumn (4,"File Name", LVCFMT_LEFT, 36 * listCtrl->GetStringWidth ("M"), 5);

	int numberOfCases = 0;

	CWinApp* pApp = AfxGetApp();
	CString lastTestCS = pApp->GetProfileString("Tests", "lastTest");
	std::string lastTest((LPCSTR) lastTestCS);
	int sel = -1;
	for (std::vector<TestInfo>::iterator it = _tests.begin (); it != _tests.end (); ++it)
	{
		std::string cbName(it->level*4, ' ');
		cbName.append(it->pTest->toString());
		comboBox->AddString (cbName.c_str ());
		if (sel < 0)
		{
			if (lastTest.empty() || lastTest == it->pTest->toString())
			{
				_selectedTest = it->pTest;
				sel = numberOfCases;
			}
		}
		numberOfCases++;
	}

	if (numberOfCases > 0)
	{
		if (sel < 0)
		{
			_selectedTest = _tests[0].pTest;
			sel = 0;
		}
		comboBox->SetCurSel (sel);
	}
	else
	{
		beRunDisabled ();
	}
	CWnd *pProgress = GetDlgItem(IDC_PROGRESS);
	CRect rect;
	pProgress->GetWindowRect(&rect);
	_testsProgress = new ProgressBar (this, rect);

	CButton* autoRunBtn = (CButton*) GetDlgItem(IDC_CHK_AUTORUN);
	autoRunBtn->SetCheck(pApp->GetProfileInt("Tests", "autoRun", BST_UNCHECKED));

	reset ();

	if (autoRunBtn->GetCheck() == BST_CHECKED)
	{
		OnRun();
	}

	return TRUE;  // return TRUE unless you set the focus to a control
					// EXCEPTION: OCX Property Pages should return FALSE
}
示例#6
0
static void
createInternalClass0(CICcontext *context, ClassClass *cb, 
		     struct Hjava_lang_ClassLoader *loader, char *name)
{
    int i, j;
    union cp_item_type *constant_pool;
    unsigned char *type_table;
    int attribute_count;
    unsigned fields_count;
    struct methodblock *mb;
    struct fieldblock *fb;
    struct Classjava_lang_Class *ucb = unhand(cb);
    
    if (get4bytes(context) != JAVA_CLASSFILE_MAGIC) 
	JAVA_ERROR(context, "Bad magic number");

    ucb->minor_version = get2bytes(context);
    ucb->major_version = get2bytes(context);
    ucb->loader = loader;
    if (ucb->major_version != JAVA_VERSION) 
	JAVA_ERROR(context, "Bad major version number");

    LoadConstantPool(context);
    constant_pool = ucb->constantpool;
    type_table = constant_pool[CONSTANT_POOL_TYPE_TABLE_INDEX].type;

    ucb->access = get2bytes(context) & ACC_WRITTEN_FLAGS;

	/* Work around javac bug */
	if (ucb->access & ACC_INTERFACE) {
		ucb->access |= ACC_ABSTRACT;
	}


    /* Get the name of the class */
    i = get2bytes(context);	/* index in constant pool of class */
    ucb->name = getAscizFromClass(context, i);
    if (name != NULL && strcmp(ucb->name, name) != 0)
	JAVA_ERROR(context, "Wrong name");
    constant_pool[i].clazz = cb;
    CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(type_table, i);

    if (loader) { 
	/* We don't trust a classloader to do the right thing. . . */
	ClassClass **pcb, **end_pcb;
	char *name = ucb->name;
	if (name == NULL || !IsLegalClassname(name, FALSE)) {
	    JAVA_ERROR(context, "Bad name");
	}
	BINCLASS_LOCK();
	for (pcb = binclasses, end_pcb = pcb + nbinclasses; 
	         pcb < end_pcb; pcb++) { 
	    ClassClass *cb = *pcb;
	    if ((cbLoader(cb) == loader) && (strcmp(name, cbName(cb)) == 0))
	        break;
	}
	BINCLASS_UNLOCK();
	if (pcb < end_pcb)
	    /* There's already a class with the same name and loader */
	    JAVA_ERROR(context, "Duplicate name");
    }

    /* Get the super class name. */
    i = get2bytes(context);	/* index in constant pool of class */
    if (i > 0) {
	ucb->super_name = getAscizFromClass(context, i);
	if (!IsLegalClassname(ucb->super_name, FALSE)) { 
	    JAVA_ERROR(context, "Bad superclass name");
	}

    } 

    i = ucb->implements_count = get2bytes(context);
    if (i > 0) {
	int j;
	ucb->implements = allocNBytes(context, i * sizeof(short));
	for (j = 0; j < i; j++) {
	    ucb->implements[j] = get2bytes(context);
	}
    }

    fields_count = ucb->fields_count = get2bytes(context);
    if (fields_count > 0) 
        ucb->fields = (struct fieldblock *)
	    allocNBytes(context, ucb->fields_count * sizeof(struct fieldblock));
    for (i = fields_count, fb = ucb->fields; --i >= 0; fb++) {
	fieldclass(fb) = cb;
	fb->access = get2bytes(context) & ACC_WRITTEN_FLAGS;
	fb->name = getAsciz(context);
	fb->signature = getAsciz(context);
	attribute_count = get2bytes(context);
	for (j = 0; j < (int)attribute_count; j++) {
	    char *name = getAsciz(context);
	    int length = get4bytes(context);
	    if ((fb->access & ACC_STATIC) 
		 && strcmp(name, "ConstantValue") == 0) {
		if (length != 2) 
		    JAVA_ERROR(context, "Wrong size for VALUE attribute");
		fb->access |= ACC_VALKNOWN;
		/* we'll change this below */
		fb->u.offset = get2bytes(context); 
	    } else {
		getNbytes(context, length, NULL);
	    }
	}
	/*
	if (fb->access & ACC_STATIC) {
	    InitializeStaticVar(fb, context);
	}
	*/
    }

    if ((ucb->methods_count = get2bytes(context)) > 0) 
	ucb->methods = (struct methodblock *)
	  allocNBytes(context, ucb->methods_count * sizeof(struct methodblock));
    for (i = cbMethodsCount(cb), mb = cbMethods(cb); --i >= 0; mb++) {
	fieldclass(&mb->fb) = cb;
	mb->fb.access = get2bytes(context) & ACC_WRITTEN_FLAGS;
	mb->fb.name = getAsciz(context);
	mb->fb.signature = getAsciz(context);

	if (strcmp(mb->fb.name, "<clinit>") == 0 &&
	    strcmp(mb->fb.signature, "()V") == 0)
	    context->in_clinit = TRUE;

	mb->args_size = Signature2ArgsSize(mb->fb.signature) 
	                + ((mb->fb.access & ACC_STATIC) ? 0 : 1);
	if (mb->args_size > 255)
	    JAVA_ERROR(context, "Too many arguments");
	attribute_count = get2bytes(context);
	for (j = 0; j < attribute_count; j++) {
	    char *attr_name = getAsciz(context);
            if ((strcmp(attr_name, "Code") == 0) 
		       && ((mb->fb.access & (ACC_NATIVE | ACC_ABSTRACT))==0)) {
		ReadInCode(context, mb);
	    } else if (strcmp(attr_name, "Exceptions") == 0) {
		ReadExceptions(context, mb);
	    } else {
		int length = get4bytes(context);
		getNbytes(context, length, NULL);
	    }
	}
	context->in_clinit = FALSE;
    }

    /* See if there are class attributes */
    attribute_count = get2bytes(context); 
    for (j = 0; j < attribute_count; j++) {
	char *name = getAsciz(context);
	int length = get4bytes(context);
	if (strcmp(name, "SourceFile") == 0) {
	    if (length != 2) {
		JAVA_ERROR(context, "Wrong size for VALUE attribute");
	    }
	    ucb->source_name = getAsciz(context);
#ifdef JCOV
	} else if (strcmp(name, "AbsoluteSourcePath") == 0) {
	    if (length == 2) {
	    	ucb->absolute_source_name = getAsciz(context);
	    } else
		getNbytes(context, length, NULL);
	} else if (strcmp(name, "TimeStamp") == 0) {
	    unsigned high;
	    unsigned low;
	    int64_t  value;
	    Java8    t1;

	    if (length == 8) {
		high = get4bytes(context);
		low  = get4bytes(context);
	    	value = ll_add(ll_shl(uint2ll(high), 32), uint2ll(low));
	    	SET_INT64(t1, &ucb->timestamp, value);
	    } else 
	    	getNbytes(context, length, NULL);
#endif
	} else {
	    getNbytes(context, length, NULL);
	}
    }
}