示例#1
0
int stringComp(Object *ptr, Object *ptr2) {
    int len = INST_DATA(ptr)[count_offset];
    int len2 = INST_DATA(ptr2)[count_offset];

    if(len == len2) {
        Object *array = (Object*)INST_DATA(ptr)[value_offset];
        Object *array2 = (Object*)INST_DATA(ptr2)[value_offset];
        int offset = INST_DATA(ptr)[offset_offset];
        int offset2 = INST_DATA(ptr2)[offset_offset];
        unsigned short *src = ((unsigned short *)ARRAY_DATA(array))+offset;
        unsigned short *dst = ((unsigned short *)ARRAY_DATA(array2))+offset2;

        for(; (len > 0) && (*src++ == *dst++); len--);

        if(len == 0)
            return TRUE;
    }

    return FALSE;
}
示例#2
0
char *String2Buff0(Object *string, char *buff, int len) {
    int offset = INST_DATA(string)[offset_offset];
    Object *array =(Object *)(INST_DATA(string)[value_offset]);
    unsigned short *str = ((unsigned short *)ARRAY_DATA(array))+offset;
    char *pntr;

    for(pntr = buff; len > 0; len--)
        *pntr++ = *str++;

    *pntr = '\0';
    return buff;
}
示例#3
0
int stringHash(Object *ptr) {
    Object *array = (Object*)INST_DATA(ptr)[value_offset];
    int len = INST_DATA(ptr)[count_offset];
    int offset = INST_DATA(ptr)[offset_offset];
    unsigned short *dpntr = ((unsigned short *)ARRAY_DATA(array))+offset;
    int hash = 0;

    for(; len > 0; len--)
        hash = hash * 37 + *dpntr++;

    return hash;
}
示例#4
0
Object *createStringFromUnicode(unsigned short *unicode, int len) {
    Object *array = allocTypeArray(T_CHAR, len);
    Object *ob = allocObject(string_class);

    if(array != NULL && ob != NULL) {
        unsigned short *data = (unsigned short *)ARRAY_DATA(array);
        memcpy(data, unicode, len*sizeof(unsigned short));

        INST_DATA(ob)[count_offset] = len;
        INST_DATA(ob)[value_offset] = (uintptr_t)array;
        return ob;
    }
    return NULL;
}
示例#5
0
// wp_next
struct
window_pane *wp_next(
	struct	window_pane *cur_wp, int dir,
	bool	(*filt)(struct window_pane *, struct window_pane *),
	int	(*sort)(const void *a, const void *b))
{
	struct	window_pane *wp;
	struct	window_pane *tar_wp;

	ARRAY_INIT(&panes);
	TAILQ_FOREACH(wp, &cur_wp->window->panes, entry)
		if (filt(cur_wp, wp))
			ARRAY_ADD(&panes, wp);

	// bypass filter
	if (ARRAY_LENGTH(&panes) == 0)
		TAILQ_FOREACH(wp, &cur_wp->window->panes, entry)
			switch(dir) {
				case WP_L:
					if (wp->xoff < cur_wp->xoff)
						ARRAY_ADD(&panes, wp);
					break;
				case WP_R:
					if (wp->xoff > cur_wp->xoff)
						ARRAY_ADD(&panes, wp);
					break;
				case WP_U:
					if (wp->yoff < cur_wp->yoff)
						ARRAY_ADD(&panes, wp);
					break;
				case WP_D:
					if (wp->yoff > cur_wp->yoff)
						ARRAY_ADD(&panes, wp);
					break;
			}

	if (ARRAY_LENGTH(&panes) > 0)
		qsort(ARRAY_DATA(&panes), ARRAY_LENGTH(&panes),
				sizeof(struct window_pane *), sort);

	if (ARRAY_LENGTH(&panes) > 0)
		tar_wp = ARRAY_FIRST(&panes);

	ARRAY_FREE(&panes);
	return tar_wp;
}
示例#6
0
Object *createString(const char* utf8) {
    int len = utf8Len(utf8);
    unsigned short *data;
    Object *array;
    Object *ob;

    if((array = allocTypeArray(T_CHAR, len)) == NULL ||
       (ob = allocObject(string_class)) == NULL)
        return NULL;

    data = (unsigned short *)ARRAY_DATA(array);
    convertUtf8(utf8, data);

    INST_DATA(ob)[count_offset] = len;
    INST_DATA(ob)[value_offset] = (uintptr_t)array;

    return ob;
}
示例#7
0
void
offArray(struct jData *jp)
{
    struct jgTreeNode *node = jp->jgrpNode;
    struct jData *jarray, *ptr;

    if (!node || node->nodeType != JGRP_NODE_ARRAY)
        return;
    jarray = ARRAY_DATA(node)->jobArray;

    for (ptr = jarray; ptr->nextJob && ptr->nextJob != jp;
         ptr = ptr->nextJob);

    if (ptr && ptr->nextJob) {
        ptr->nextJob = ptr->nextJob->nextJob;
    }

    updJgrpCountByJStatus(jp, jp->jStatus, JOB_STAT_NULL);
}
示例#8
0
/* handleNewJobArray()
 */
void
handleNewJobArray(struct jData *jarray,
                  struct idxList *idxList,
                  int maxJLimit)
{
    struct idxList *idxPtr;
    struct jData *jPtr;
    int numJobs = 0;
    int i;
    int userPending = 0;

    addJobIdHT(jarray);
    jarray->nodeType = JGRP_NODE_ARRAY;
    jarray->nextJob = NULL;

    if (mSchedStage != M_STAGE_REPLAY) {
        putOntoTree(jarray, JOB_NEW);
    } else {
        putOntoTree(jarray, JOB_REPLAY);
    }

    jarray->uPtr = getUserData(jarray->userName);

    if (jarray->shared->jobBill.options2 & SUB2_HOLD) {
        userPending = 1;
    }

    jPtr = jarray;
    for (idxPtr = idxList; idxPtr; idxPtr = idxPtr->next) {

        for (i = idxPtr->start; i <= idxPtr->end; i += idxPtr->step) {
            if (getJobData(LSB_JOBID((LS_LONG_INT)jarray->jobId, i)))
                continue;
            jPtr->nextJob = copyJData(jarray);
            numJobs++;
            jPtr = jPtr->nextJob;

            jPtr->nodeType = JGRP_NODE_JOB;
            jPtr->nextJob = NULL;
            jPtr->jobId = LSB_JOBID((LS_LONG_INT)jarray->jobId, i);
            addJobIdHT(jPtr);
            inPendJobList(jPtr, PJL, 0);
            if (userPending) {
                jPtr->newReason = PEND_USER_STOP;
                jPtr->jStatus = JOB_STAT_PSUSP;
            }
        }
    }

    ARRAY_DATA(jarray->jgrpNode)->maxJLimit = maxJLimit;

    if (mSchedStage != M_STAGE_REPLAY)
        log_newjob(jarray);

    if (mSchedStage != M_STAGE_REPLAY) {
        updQaccount(jarray,
                    jarray->shared->jobBill.maxNumProcessors * numJobs,
                    jarray->shared->jobBill.maxNumProcessors * numJobs,
                    0,
                    0,
                    0,
                    0);
        updUserData(jarray,
                    jarray->shared->jobBill.maxNumProcessors * numJobs,
                    jarray->shared->jobBill.maxNumProcessors * numJobs,
                    0,
                    0,
                    0,
                    0);
    }

    if (mSchedStage == M_STAGE_REPLAY) {

        if (maxUserPriority > 0) {
            if (jarray->shared->jobBill.userPriority < 0) {

                modifyJobPriority(jarray, maxUserPriority/2);
                for (jPtr = jarray->nextJob; jPtr; jPtr = jPtr->nextJob) {
                    modifyJobPriority(jPtr, maxUserPriority/2);
                }
            } else {
                modifyJobPriority(jarray,
                                  jarray->shared->jobBill.userPriority);
                for (jPtr = jarray->nextJob; jPtr; jPtr = jPtr->nextJob) {
                    modifyJobPriority(jPtr,
                                      jPtr->shared->jobBill.userPriority);
                }
            }
        }
    }

    ARRAY_DATA(jarray->jgrpNode)->counts[getIndexOfJStatus(jarray->nextJob->jStatus)] = numJobs;
    ARRAY_DATA(jarray->jgrpNode)->counts[JGRP_COUNT_NJOBS] = numJobs;
    updJgrpCountByOp(jarray->jgrpNode, 1);
}
示例#9
0
unsigned short *getStringChars(Object *string) {
    Object *array = (Object*)INST_DATA(string)[value_offset];
    int offset = INST_DATA(string)[offset_offset];
    return ((unsigned short*)ARRAY_DATA(array))+offset;
}
示例#10
0
文件: jam.c 项目: OPSF/uClinux
int main(int argc, char *argv[]) {
    Class *array_class, *main_class;
    Object *system_loader, *array;
    MethodBlock *mb;
    InitArgs args;
    int class_arg;
    char *cpntr;
    int status;
    int i;

    setDefaultInitArgs(&args);
    class_arg = parseCommandLine(argc, argv, &args);

    args.main_stack_base = &array_class;
    initVM(&args);

   if((system_loader = getSystemClassLoader()) == NULL) {
        printf("Cannot create system class loader\n");
        printException();
        exitVM(1);
    }

    mainThreadSetContextClassLoader(system_loader);

    for(cpntr = argv[class_arg]; *cpntr; cpntr++)
        if(*cpntr == '.')
            *cpntr = '/';

    if((main_class = findClassFromClassLoader(argv[class_arg], system_loader)) != NULL)
        initClass(main_class);

    if(exceptionOccurred()) {
        printException();
        exitVM(1);
    }

    mb = lookupMethod(main_class, SYMBOL(main), SYMBOL(_array_java_lang_String__V));
    if(!mb || !(mb->access_flags & ACC_STATIC)) {
        printf("Static method \"main\" not found in %s\n", argv[class_arg]);
        exitVM(1);
    }

    /* Create the String array holding the command line args */

    i = class_arg + 1;
    if((array_class = findArrayClass(SYMBOL(array_java_lang_String))) &&
           (array = allocArray(array_class, argc - i, sizeof(Object*))))  {
        Object **args = (Object**)ARRAY_DATA(array) - i;

        for(; i < argc; i++)
            if(!(args[i] = Cstr2String(argv[i])))
                break;

        /* Call the main method */
        if(i == argc)
            executeStaticMethod(main_class, mb, array);
    }

    /* ExceptionOccurred returns the exception or NULL, which is OK
       for normal conditionals, but not here... */
    if((status = exceptionOccurred() ? 1 : 0))
        printException();

    /* Wait for all but daemon threads to die */
    mainThreadWaitToExitVM();
    exitVM(status);
}
示例#11
0
void
java_lang_VMSystem_arraycopy0(struct Hjava_lang_Object* src,
			      jint srcpos,
			      struct Hjava_lang_Object* dst,
			      jint dstpos,
			      jint len)
{
	char* in; 	 
	char* out; 	 
	int elemsz; 	 
	Hjava_lang_Class* sclass; 	 
	Hjava_lang_Class* dclass;

	sclass = OBJECT_CLASS(src); 	 
	dclass = OBJECT_CLASS(dst);

	sclass = Kaffe_get_array_element_type(sclass); 	 
	dclass = Kaffe_get_array_element_type(dclass); 	 
	elemsz = TYPE_SIZE(sclass); 	 

	len *= elemsz; 	 
	srcpos *= elemsz; 	 
	dstpos *= elemsz; 	 

	in = &((char*)ARRAY_DATA(src))[srcpos]; 	 
	out = &((char*)ARRAY_DATA(dst))[dstpos];

	if (sclass == dclass) {
#if defined(HAVE_MEMMOVE) 	 
		memmove((void*)out, (void*)in, (size_t)len); 	 
#else 	 
		/* Do it ourself */ 	 
#if defined(HAVE_MEMCPY) 	 
		if (src != dst) { 	 
			memcpy((void*)out, (void*)in, (size_t)len); 	 
		} else 	 
#endif 	 
		if (out < in) { 	 
			/* Copy forwards */ 	 
			for (; len > 0; len--) { 	 
				*out++ = *in++; 	 
			} 	 
		} else { 	 
			/* Copy backwards */ 	 
			out += len; 	 
			in += len; 	 
			for (; len > 0; len--) { 	 
				*--out = *--in; 	 
			} 	 
		} 	 
#endif 	 
	} else {
		if (CLASS_IS_PRIMITIVE(sclass) || CLASS_IS_PRIMITIVE(dclass)) {
		  Hjava_lang_Throwable* asexc;
		  const char *stype = CLASS_CNAME(sclass);
		  const char *dtype = CLASS_CNAME(dclass);
		  char *b;
#define _FORMAT "incompatible array types `%s' and `%s'"
		  b = checkPtr(KMALLOC(strlen(stype)+strlen(dtype)+strlen(_FORMAT)));
		  sprintf(b, _FORMAT, stype, dtype);
#undef _FORMAT
		  asexc = ArrayStoreException(b);
		  KFREE(b);
		  throwException(asexc);
		}

		for (; len > 0; len -= sizeof(Hjava_lang_Object*)) { 	 
			Hjava_lang_Object* val = *(Hjava_lang_Object**)in; 	 
			if (val != 0 && !instanceof(dclass, OBJECT_CLASS(val))) { 	 
			  Hjava_lang_Throwable* asexc;
			  const char *vtype = CLASS_CNAME(OBJECT_CLASS(val));
			  const char *atype = CLASS_CNAME(dclass);
			  char *b;
#define _FORMAT "can't store `%s' in array of type `%s'"
			  b = checkPtr(KMALLOC(strlen(vtype)+strlen(atype)+strlen(_FORMAT)));
			  sprintf(b, _FORMAT, vtype, atype);
#undef _FORMAT
			  asexc = ArrayStoreException(b);
			  KFREE(b);
			  throwException(asexc);
			}
			*(Hjava_lang_Object**)out = val; 	 
			in += sizeof(Hjava_lang_Object*); 	 
			out += sizeof(Hjava_lang_Object*); 	 
		}
	}
}