/* ** Allocate cleared (zeroed) memory. */ void * _allocClearedMem(w_size rsize) { w_chunk chunk; w_thread thread = currentWonkaThread; gc_reclaim(rsize, NULL); if (pre_alloc_check(thread, rsize)) { alloc_barrier(thread); chunk = x_mem_calloc(sizeof(w_Chunk) + rsize); } else { chunk = NULL; } if (chunk) { post_alloc(thread, chunk); } else { w_printf("Failed to allocate %d bytes\n", rsize); if (thread && thread->Thread && isNotSet(thread->flags, WT_THREAD_THROWING_OOME)) { throwOutOfMemoryError(thread, rsize); } return NULL; } return chunk->data; }
void * _d_allocClearedMem(w_size rsize, const char * file, const int line) { w_chunk chunk; w_thread thread = currentWonkaThread; woempa(1,"%s.%d: Requested %d bytes, allocating %d bytes\n", file, line, rsize, sizeof(w_Chunk) + rsize); if (pre_alloc_check(thread, rsize)) { alloc_barrier(thread); x_mem_lock(x_eternal); chunk = _x_mem_calloc(sizeof(w_Chunk) + rsize, file, line); } else { chunk = NULL; } if (!chunk) { x_mem_unlock(); woempa(9, "Failed to allocate %d bytes\n", rsize); if (thread && thread->Thread && isNotSet(thread->flags, WT_THREAD_THROWING_OOME)) { throwOutOfMemoryError(thread, rsize); } return NULL; } post_alloc(thread, chunk); woempa(1,"%s.%d: Allocated %d bytes at %p\n", file, line, rsize, chunk); prepareChunk(chunk, rsize, file, line); x_mem_unlock(); checkChunk(chunk->data, 1, file, line); return chunk->data; }
void * _reallocMem(void * block, w_size newsize) { w_chunk oldchunk; w_size oldsize; w_chunk newchunk; w_thread thread = currentWonkaThread; oldchunk = block2chunk(block); oldsize = x_mem_size(oldchunk); gc_reclaim(newsize - oldsize, NULL); if (pre_realloc_check(thread, newsize, oldsize)) { alloc_barrier(thread); newchunk = x_mem_realloc(oldchunk, sizeof(w_Chunk) + newsize); } else { newchunk = NULL; } if (newchunk) { post_alloc(thread, newchunk); } else { w_printf("Failed to reallocate %d bytes\n", newsize); if (thread && thread->Thread && isNotSet(thread->flags, WT_THREAD_THROWING_OOME)) { throwOutOfMemoryError(thread, newsize); } return NULL; } return newchunk->data; }
w_void jdwp_thr_countframes(jdwp_command_packet cmd) { w_size offset = 0; w_thread thread; w_instance instance; w_frame cursor; w_int count = 0; instance = jdwp_get_objectref(cmd->data, &offset); woempa(7, "%j\n", instance); if (instance) { thread = jdwp_check_thread_reference(instance); woempa(7, "%t\n", thread); if (thread) { if(thread->kthread->state == xt_suspended || isSet(thread->flags, WT_THREAD_SUSPEND_COUNT_MASK) || jdwp_global_suspend_count) { cursor = thread->top; while(cursor) { count += isNotSet(cursor->flags, JDWP_IGNORE_FRAME);; cursor = cursor->previous; } jdwp_put_u4(&reply_grobag, count); jdwp_send_reply(cmd->id, &reply_grobag, jdwp_err_none); } else { jdwp_send_thread_not_suspended(cmd->id); } } else { jdwp_send_invalid_thread(cmd->id); } } else { jdwp_send_invalid_object(cmd->id); } }
void * _d_reallocMem(void * block, w_size newsize, const char * file, const int line) { w_chunk oldchunk; w_chunk newchunk; w_size oldsize; w_thread thread = currentWonkaThread; woempa(1,"%s.%d: Reallocating block %p, new size = %d\n", file, line, block, newsize); oldchunk = checkChunk(block, 1, file, line); if (!oldchunk) { woempa(9, "Failed to reallocate %d bytes for %s:%d\n", newsize, file, line); return NULL; } pre_dealloc(thread, oldchunk, 0); oldsize = x_mem_size(oldchunk); woempa(1,"%s.%d: Requested %d bytes, allocating %d bytes\n", file, line, newsize, sizeof(w_Chunk) + newsize); gc_reclaim(newsize - oldsize, NULL); if (pre_realloc_check(thread, newsize, oldsize)) { alloc_barrier(thread); x_mem_lock(x_eternal); newchunk = _x_mem_realloc(oldchunk, sizeof(w_Chunk) + newsize, file, line); } else { newchunk = NULL; } if (newchunk) { post_alloc(thread, newchunk); } else { x_mem_unlock(); printf("Failed to reallocate %d bytes for %s:%d\n", newsize, file, line); if (thread && thread->Thread && isNotSet(thread->flags, WT_THREAD_THROWING_OOME)) { throwOutOfMemoryError(thread, newsize); } return NULL; } woempa(1,"%s.%d: Reallocated %d bytes at %p\n", file, line, newsize, newchunk); prepareChunk(newchunk, newsize, file, line); x_mem_unlock(); checkChunk(newchunk->data, 1, file, line); return newchunk->data; }
/* ** Check that the given objectref really is a Thread. If it is, return the ** correcponding w_thread, otherwise return NULL. */ w_thread jdwp_check_thread_reference(w_instance instance) { w_thread thread; if (!isProbablyAnInstance(instance)) { woempa(7, "%p is not an instance!\n", instance); return NULL; } if (isNotSet(instance2clazz(instance)->flags, CLAZZ_IS_THREAD)) { woempa(7, "%j is not a Thread!\n", instance); return NULL; } thread = getWotsitField(instance, F_Thread_wotsit); if (!thread || (thread == (w_thread)0xaaaaaaaa) || strncmp(thread->label, "thread", 6) != 0) { woempa(7, "%p is not a w_thread!\n", thread); return NULL; } return thread; }
w_int loadSuperClasses(w_clazz clazz, w_thread thread) { w_clazz super; w_int i; w_int n; w_int result = CLASS_LOADING_DID_NOTHING; #ifndef NO_FORMAT_CHECKS if (isNotSet(clazz->flags, CLAZZ_IS_TRUSTED) && !clazz->temp.super_index) { throwException(thread, clazzVerifyError, "Class %k has no superclass", clazz); return CLASS_LOADING_FAILED; } #endif clazz->supers = allocMem(MAX_SUPER_CLASSES * sizeof(w_clazz)); if (!clazz->supers) { return CLASS_LOADING_FAILED; } super = clazz; n = MAX_SUPER_CLASSES; for (i = 0; i < MAX_SUPER_CLASSES; ++i) { if (!super->temp.super_index) { woempa(1, "Reached top of hierarchy after %d class(es): %k\n", i, super); n = i; break; } #ifndef NO_FORMAT_CHECKS if (isNotSet(super->flags, CLAZZ_IS_TRUSTED) && !isClassConstant(super, super->temp.super_index)) { throwException(thread, clazzClassFormatError, "Superclass of %k is not a class constant (is %02x)", super, super->tags[super->temp.super_index]); return CLASS_LOADING_FAILED; } #endif super = getClassConstant(super, super->temp.super_index, thread); if (!super) { throwException(thread, clazzLinkageError, "Cannot resolve superclass of %k", clazz); return CLASS_LOADING_FAILED; } clazz->supers[i] = super; woempa(1, "Class %k supers[%d] = %k\n", clazz, i, super); if (getClazzState(super) >= CLAZZ_STATE_SUPERS_LOADED) { woempa(1, "Class %k is already supersLoaded, has %d superclasses => depth of %k is %d\n", super, super->numSuperClasses, clazz, i + super->numSuperClasses + 1); n = i + super->numSuperClasses + 1; break; } } if (n == MAX_SUPER_CLASSES) { wabort(ABORT_WONKA, "Class %k has too many superclasses", clazz); } for (i= i + 1; i < n; ++i) { woempa(1, "Copying %k (superclass[%d] of %k) as superclass[%d] of %k\n", super->supers[i - n + super->numSuperClasses], i - n + super->numSuperClasses, super, i, clazz); clazz->supers[i] = super->supers[i - n + super->numSuperClasses]; } woempa(1, "Class %k has total of %d superclasses\n", clazz, n); clazz->supers = reallocMem(clazz->supers, n * sizeof(w_clazz)); if (!clazz->supers) { return CLASS_LOADING_FAILED; } clazz->numSuperClasses = n; super = clazz->supers[0]; #ifndef NO_HIERARCHY_CHECKS if (isNotSet(super->flags, CLAZZ_IS_TRUSTED)) { if (isSet(clazz->flags, ACC_INTERFACE) && super != clazzObject) { throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is an interface", super, clazz); return CLASS_LOADING_FAILED; } if (isSet(super->flags, ACC_FINAL)) { woempa(9, "Violation of J+JVM Constraint 4.1.1, item 2\n"); throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is final", super, clazz); return CLASS_LOADING_FAILED; } if (isNotSet(super->flags, ACC_PUBLIC) && !sameRuntimePackage(clazz, super)) { woempa(9, "Violation of J+JVM Constraint 4.1.4\n"); throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is not accessible", super, clazz); return CLASS_LOADING_FAILED; } } #endif for (i = n - 1; i >= 0; --i) { result |= mustBeSupersLoaded(clazz->supers[i]); if (result == CLASS_LOADING_FAILED || exceptionThrown(thread)) { return CLASS_LOADING_FAILED; } } clazz->flags |= super->flags & CLAZZ_HERITABLE_FLAGS; return CLASS_LOADING_SUCCEEDED; }
w_void jdwp_thr_frames(jdwp_command_packet cmd) { w_size offset = 0; w_thread thread; w_instance instance; w_int start; w_int length; w_frame cursor; w_frame top; w_int count = 0; jdwp_Location location; w_frame frame; w_clazz clazz; w_method method; w_long pc; instance = jdwp_get_objectref(cmd->data, &offset); woempa(7, "%j\n", instance); if (instance) { thread = jdwp_check_thread_reference(instance); woempa(7, "%t\n", thread); if (thread) { start = jdwp_get_u4(cmd->data, &offset); length = jdwp_get_u4(cmd->data, &offset); woempa(7, "Request is for %d frames starting with frame %d\n", length, start); if(thread->kthread->state == xt_suspended || isSet(thread->flags, WT_THREAD_SUSPEND_COUNT_MASK) || jdwp_global_suspend_count) { cursor = thread->top; woempa(7, " top frame is at %p\n", cursor); while(cursor && cursor->method && count < start) { count += isNotSet(cursor->flags, JDWP_IGNORE_FRAME); cursor = cursor->previous; } top = cursor; woempa(7, " skipped %d frames, now at %p\n", count, cursor); /* ** Count the remaining frames. */ count = 0; while(cursor && cursor->method && (length == -1 ? 1 : (count < length))) { count += isNotSet(cursor->flags, JDWP_IGNORE_FRAME); cursor = cursor->previous; } woempa(7, " will give back %d frames\n", count); jdwp_put_u4(&reply_grobag, count); cursor = top; count = 0; while(cursor && cursor->method && (length == -1 ? 1 : (count < length))) { if (isNotSet(cursor->flags, JDWP_IGNORE_FRAME)) { frame = cursor; woempa(7, " frame at %p (%m)\n", frame, frame->method); jdwp_put_frame(&reply_grobag, frame); method = cursor->method; clazz = method->spec.declaring_clazz; pc = frame->current - method->exec.code; location.method = method; location.pc = pc; jdwp_put_location(&reply_grobag, &location); count++; } cursor = cursor->previous; } jdwp_send_reply(cmd->id, &reply_grobag, jdwp_err_none); } else { jdwp_send_thread_not_suspended(cmd->id); } } else { jdwp_send_invalid_thread(cmd->id); } } else { jdwp_send_invalid_object(cmd->id); } }