VMEXPORT // temporary solution for interpreter unplug Vector_Handle vm_new_vector_primitive(Class *vector_class, int length) { ASSERT_RAISE_AREA; assert(!hythread_is_suspend_enabled()); assert(vector_class->is_array_of_primitives()); unsigned sz = vector_class->calculate_array_size(length); if (sz == 0) { tmn_suspend_enable(); if (length < 0) { exn_raise_by_name("java/lang/NegativeArraySizeException"); } else { exn_raise_by_name("java/lang/OutOfMemoryError", "VM doesn't support arrays of the requested size"); } tmn_suspend_disable(); return NULL; } Vector_Handle vector = (Vector_Handle)gc_alloc(sz, vector_class->get_allocation_handle(), vm_get_gc_thread_local()); #ifdef VM_STATS vector_class->instance_allocated(sz); #endif //VM_STATS if (NULL == vector) { exn_raise_object( VM_Global_State::loader_env->java_lang_OutOfMemoryError); return 0; } set_vector_length(vector, length); assert(get_vector_vtable(vector) == vector_class->get_vtable()); return vector; }
jint JNICALL Java_java_lang_Runtime_00024SubProcess_00024SubInputStream_available0 ( JNIEnv *env, jobject obj, jlong inputHandle) { DWORD totalBytesAvail; if (!PeekNamedPipe((HANDLE)(POINTER_SIZE_INT)inputHandle /* handle to pipe to copy from */, NULL /* pointer to data buffer */, NULL /* size, in bytes, of data buffer */, NULL /* pointer to number of bytes read */, &totalBytesAvail /* pointer to total number of bytes available */, NULL /* pointer to unread bytes in this message */ )) { DWORD error = GetLastError(); INFO("Subprocess input stream access failed; error code = " << error); switch (error) { case ERROR_HANDLE_EOF: //Reached the end of the file. case ERROR_NO_DATA: //The pipe is being closed. case ERROR_BROKEN_PIPE: //The pipe has been ended. break; default: exn_raise_by_name("java/io/IOException"); } return 0; } TRACE("Subprocess input stream " << inputHandle << " has " << totalBytesAvail << " bytes available"); return totalBytesAvail; }
bool field_can_link(Class* clss, Field* field, bool _static, bool putfield, bool _throw) { ASSERT_RAISE_AREA; if(_static?(!field->is_static()):(field->is_static())) { if(_throw) { exn_raise_by_name("java/lang/IncompatibleClassChangeError", field->get_class()->get_name()->bytes); } return false; } if(putfield && field->is_final()) { for(int fn = 0; fn < clss->get_number_of_fields(); fn++) { if(clss->get_field(fn) == field) { return true; } } if(_throw) { unsigned buf_size = clss->get_name()->len + field->get_class()->get_name()->len + field->get_name()->len + 15; char* buf = (char*)STD_ALLOCA(buf_size); memset(buf, 0, buf_size); sprintf(buf, " from %s to %s.%s", clss->get_name()->bytes, field->get_class()->get_name()->bytes, field->get_name()->bytes); jthrowable exc_object = exn_create("java/lang/IllegalAccessError", buf); exn_raise_object(exc_object); } return false; } return true; }
static bool class_can_instantiate(Class* clss, bool _throw) { ASSERT_RAISE_AREA; bool fail = clss->is_abstract(); if(fail && _throw) { exn_raise_by_name("java/lang/InstantiationError", clss->get_name()->bytes); } return !fail; }
static bool method_can_link_special(Class* clss, unsigned index, Method* method, bool _throw) { ASSERT_RAISE_AREA; ConstantPool& cp = clss->get_constant_pool(); unsigned class_idx = cp.get_ref_class_index(index); unsigned class_name_idx = cp.get_class_name_index(class_idx); String* ref_class_name = cp.get_utf8_string(class_name_idx); if(method->get_name() == VM_Global_State::loader_env->Init_String && method->get_class()->get_name() != ref_class_name) { if(_throw) { exn_raise_by_name("java/lang/NoSuchMethodError", method->get_name()->bytes); } return false; } if(method->is_static()) { if(_throw) { exn_raise_by_name("java/lang/IncompatibleClassChangeError", method->get_class()->get_name()->bytes); } return false; } if(method->is_abstract()) { if(_throw) { tmn_suspend_enable(); unsigned buf_size = clss->get_name()->len + method->get_name()->len + method->get_descriptor()->len + 5; char* buf = (char*)STD_ALLOCA(buf_size); memset(buf, 0, buf_size); sprintf(buf, "%s.%s%s", clss->get_name()->bytes, method->get_name()->bytes, method->get_descriptor()->bytes); jthrowable exc_object = exn_create("java/lang/AbstractMethodError", buf); exn_raise_object(exc_object); tmn_suspend_disable(); } return false; } return true; }
static Vector_Handle vm_anewarray_resolved_array_type(Class *arr_clss, int length) { #ifdef VM_STATS UNSAFE_REGION_START VM_Statistics::get_vm_stats().num_anewarray++; UNSAFE_REGION_END #endif ASSERT_RAISE_AREA; assert(!hythread_is_suspend_enabled()); assert(!arr_clss->is_array_of_primitives()); unsigned sz = arr_clss->calculate_array_size(length); if (sz == 0) { tmn_suspend_enable(); if (length < 0) { exn_raise_by_name("java/lang/NegativeArraySizeException"); } else { exn_raise_by_name("java/lang/OutOfMemoryError", "VM doesn't support arrays of the requested size"); } tmn_suspend_disable(); return NULL; } assert((sz & NEXT_TO_HIGH_BIT_SET_MASK) == 0); Vector_Handle object_array = (Vector_Handle )gc_alloc(sz, arr_clss->get_allocation_handle(), vm_get_gc_thread_local()); #ifdef VM_STATS arr_clss->instance_allocated(sz); #endif //VM_STATS if (NULL == object_array) { exn_raise_object( VM_Global_State::loader_env->java_lang_OutOfMemoryError); return NULL; } set_vector_length(object_array, length); assert(get_vector_vtable(object_array) == arr_clss->get_vtable()); return object_array; } //vm_anewarray_resolved_array_type
static bool method_can_link_static(Class* clss, unsigned index, Method* method, bool _throw) { ASSERT_RAISE_AREA; if (!method->is_static()) { if(_throw) { exn_raise_by_name("java/lang/IncompatibleClassChangeError", method->get_class()->get_name()->bytes); } return false; } return true; }
static bool method_can_link_virtual(Class* clss, unsigned cp_index, Method* method, bool _throw) { ASSERT_RAISE_AREA; if(method->is_static()) { if(_throw) { exn_raise_by_name("java/lang/IncompatibleClassChangeError", method->get_class()->get_name()->bytes); } return false; } if(method->get_class()->is_interface()) { if(_throw) { char* buf = (char*)STD_ALLOCA(clss->get_name()->len + method->get_name()->len + method->get_descriptor()->len + 2); sprintf(buf, "%s.%s%s", clss->get_name()->bytes, method->get_name()->bytes, method->get_descriptor()->bytes); jthrowable exc_object = exn_create("java/lang/AbstractMethodError", buf); exn_raise_object(exc_object); } return false; } return true; }
void exn_raise_by_name(const char* exc_name, const char* exc_message) { exn_raise_by_name(exc_name, exc_message, NULL); }
void exn_raise_by_name(const char* exc_name, jthrowable exc_cause) { exn_raise_by_name(exc_name, NULL, exc_cause); }
void exn_raise_by_name(const char* exc_name) { exn_raise_by_name(exc_name, NULL, NULL); }