#include <java/lang/StringBuffer.h>
#include <java/lang/Class.h>
#include <java/lang/reflect/Modifier.h>
-#include <java/lang/VirtualMachineError.h>
#include <java/lang/InternalError.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/ArithmeticException.h>
__attribute__ ((__noreturn__));
static void throw_incompatible_class_change_error (jstring msg)
__attribute__ ((__noreturn__));
-#ifndef HANDLE_SEGV
static void throw_null_pointer_exception ()
__attribute__ ((__noreturn__));
-#endif
static void throw_class_format_error (jstring msg)
__attribute__ ((__noreturn__));
#define SAVE_PC() frame_desc.pc = pc
+// We used to define this conditionally, depending on HANDLE_SEGV.
+// However, that runs into a problem if a chunk in low memory is
+// mapped and we try to look at a field near the end of a large
+// object. See PR 26858 for details. It is, most likely, relatively
+// inexpensive to simply do this check always.
+#define NULLCHECK(X) \
+ do { SAVE_PC(); if ((X)==NULL) throw_null_pointer_exception (); } while (0)
+
+// Note that we can still conditionally define NULLARRAYCHECK, since
+// we know that all uses of an array will first reference the length
+// field, which is first -- and thus will trigger a SEGV.
#ifdef HANDLE_SEGV
-#define NULLCHECK(X) SAVE_PC()
#define NULLARRAYCHECK(X) SAVE_PC()
#else
-#define NULLCHECK(X) \
- do { SAVE_PC(); if ((X)==NULL) throw_null_pointer_exception (); } while (0)
#define NULLARRAYCHECK(X) \
do { SAVE_PC(); if ((X)==NULL) { throw_null_pointer_exception (); } } while (0)
#endif
exc[i].start_pc.p = &insns[pc_mapping[exc[i].start_pc.i]];
exc[i].end_pc.p = &insns[pc_mapping[exc[i].end_pc.i]];
exc[i].handler_pc.p = &insns[pc_mapping[exc[i].handler_pc.i]];
+ // FIXME: resolve_pool_entry can throw - we shouldn't be doing this
+ // during compilation.
jclass handler
= (_Jv_Linker::resolve_pool_entry (defining_class,
exc[i].handler_type.i)).clazz;
// destructor so it cleans up automatically when the interpreter
// returns.
java::lang::Thread *thread = java::lang::Thread::currentThread();
- _Jv_InterpFrame frame_desc (meth,
- (_Jv_InterpFrame **) &thread->interp_frame);
+ _Jv_InterpFrame frame_desc (meth, thread);
_Jv_word stack[meth->max_stack];
_Jv_word *sp = stack;
insn_invokevirtual: // 0xb6
{
+ SAVE_PC();
int index = GET2U ();
/* _Jv_Linker::resolve_pool_entry returns immediately if the
* the corresponding bit JV_CONSTANT_ResolvedFlag in the tag
* directly. For now, I don't think it is worth it. */
- SAVE_PC();
rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
index)).rmethod;
sp -= rmeth->stack_item_count;
- // We don't use NULLCHECK here because we can't rely on that
- // working if the method is final. So instead we do an
- // explicit test.
- if (! sp[0].o)
- {
- //printf("invokevirtual pc = %p/%i\n", pc, meth->get_pc_val(pc));
- throw new java::lang::NullPointerException;
- }
- if (rmeth->vtable_index == -1)
+ if (rmeth->method->accflags & Modifier::FINAL)
{
- // final methods do not appear in the vtable,
- // if it does not appear in the superclass.
+ // We can't rely on NULLCHECK working if the method is final.
+ if (! sp[0].o)
+ throw_null_pointer_exception ();
+
+ // Final methods might not appear in the vtable.
fun = (void (*)()) rmeth->method->ncode;
}
else
{
+ NULLCHECK (sp[0].o);
jobject rcv = sp[0].o;
_Jv_VTable *table = *(_Jv_VTable**) rcv;
- fun = (void (*)()) table->get_method (rmeth->vtable_index);
+ fun = (void (*)()) table->get_method (rmeth->method->index);
}
#ifdef DIRECT_THREADED
#ifdef DIRECT_THREADED
invokevirtual_resolved:
{
+ SAVE_PC();
rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count;
- // We don't use NULLCHECK here because we can't rely on that
- // working if the method is final. So instead we do an
- // explicit test.
- if (! sp[0].o)
- {
- SAVE_PC();
- throw new java::lang::NullPointerException;
- }
- if (rmeth->vtable_index == -1)
+ if (rmeth->method->accflags & Modifier::FINAL)
{
- // final methods do not appear in the vtable,
- // if it does not appear in the superclass.
+ // We can't rely on NULLCHECK working if the method is final.
+ if (! sp[0].o)
+ throw_null_pointer_exception ();
+
+ // Final methods might not appear in the vtable.
fun = (void (*)()) rmeth->method->ncode;
}
else
{
jobject rcv = sp[0].o;
_Jv_VTable *table = *(_Jv_VTable**) rcv;
- fun = (void (*)()) table->get_method (rmeth->vtable_index);
+ fun = (void (*)()) table->get_method (rmeth->method->index);
}
}
goto perform_invoke;
perform_invoke:
{
- SAVE_PC();
-
/* here goes the magic again... */
ffi_cif *cif = &rmeth->cif;
ffi_raw *raw = (ffi_raw*) sp;
// For direct threaded we have a separate 'ldc class' operation.
insn_ldc_class:
{
+ SAVE_PC();
// We could rewrite the instruction at this point.
int index = INTVAL ();
jobject k = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
insn_idiv:
{
+ SAVE_PC();
jint value2 = POPI();
jint value1 = POPI();
jint res = _Jv_divI (value1, value2);
insn_ldiv:
{
+ SAVE_PC();
jlong value2 = POPL();
jlong value1 = POPL();
jlong res = _Jv_divJ (value1, value2);
insn_fdiv:
{
+ SAVE_PC();
jfloat value2 = POPF();
jfloat value1 = POPF();
jfloat res = value1 / value2;
insn_irem:
{
+ SAVE_PC();
jint value2 = POPI();
jint value1 = POPI();
jint res = _Jv_remI (value1, value2);
insn_lrem:
{
+ SAVE_PC();
jlong value2 = POPL();
jlong value1 = POPL();
jlong res = _Jv_remJ (value1, value2);
insn_getfield:
{
+ SAVE_PC();
jint fieldref_index = GET2U ();
_Jv_Linker::resolve_pool_entry (meth->defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field;
jclass type = field->type;
jint field_offset = field->u.boffset;
- if (field_offset > 0xffff)
- throw new java::lang::VirtualMachineError;
jobject obj = POPA();
NULLCHECK(obj);
insn_putstatic:
{
+ SAVE_PC();
jint fieldref_index = GET2U ();
_Jv_Linker::resolve_pool_entry (meth->defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field;
insn_putfield:
{
+ SAVE_PC();
jint fieldref_index = GET2U ();
_Jv_Linker::resolve_pool_entry (meth->defining_class, fieldref_index);
_Jv_Field *field = pool_data[fieldref_index].field;
(JvNewStringLatin1 ("field is static"));
jint field_offset = field->u.boffset;
- if (field_offset > 0xffff)
- throw new java::lang::VirtualMachineError;
void *newinsn = NULL;
if (type->isPrimitive ())
insn_invokespecial:
{
+ SAVE_PC();
int index = GET2U ();
rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
if (! sp[0].o)
{
SAVE_PC();
- throw new java::lang::NullPointerException;
+ throw_null_pointer_exception ();
}
fun = (void (*)()) rmeth->method->ncode;
#ifdef DIRECT_THREADED
invokespecial_resolved:
{
+ SAVE_PC();
rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count;
// We don't use NULLCHECK here because we can't rely on that
// working for <init>. So instead we do an explicit test.
if (! sp[0].o)
{
- SAVE_PC();
- throw new java::lang::NullPointerException;
+ throw_null_pointer_exception ();
}
fun = (void (*)()) rmeth->method->ncode;
}
insn_invokestatic:
{
+ SAVE_PC();
int index = GET2U ();
rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
#ifdef DIRECT_THREADED
invokestatic_resolved:
{
+ SAVE_PC();
rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count;
fun = (void (*)()) rmeth->method->ncode;
insn_invokeinterface:
{
+ SAVE_PC();
int index = GET2U ();
rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
#ifdef DIRECT_THREADED
invokeinterface_resolved:
{
+ SAVE_PC();
rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count;
jobject rcv = sp[0].o;
insn_new:
{
+ SAVE_PC();
int index = GET2U ();
jclass klass = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
index)).clazz;
insn_anewarray:
{
+ SAVE_PC();
int index = GET2U ();
jclass klass = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
index)).clazz;
insn_multianewarray:
{
+ SAVE_PC();
int kind_index = GET2U ();
int dim = GET1U ();
throw new java::lang::IncompatibleClassChangeError (msg);
}
-#ifndef HANDLE_SEGV
-static java::lang::NullPointerException *null_pointer_exc;
static void
throw_null_pointer_exception ()
{
- if (null_pointer_exc == NULL)
- null_pointer_exc = new java::lang::NullPointerException;
-
- throw null_pointer_exc;
+ throw new java::lang::NullPointerException;
}
-#endif
/* Look up source code line number for given bytecode (or direct threaded
interpreter) PC. */
_Jv_InterpClass *iclass = (_Jv_InterpClass *) klass->aux_info;
// Splitting the allocations here lets us scan reference fields and
- // avoid scanning non-reference fields.
+ // avoid scanning non-reference fields. How reference fields are
+ // scanned is a bit tricky: we allocate using _Jv_AllocRawObj, which
+ // means that this memory will be scanned conservatively (same
+ // difference, since we know all the contents here are pointers).
+ // Then we put pointers into this memory into the 'fields'
+ // structure. Most of these are interior pointers, which is ok (but
+ // even so the pointer to the first reference field will be used and
+ // that is not an interior pointer). The 'fields' array is also
+ // allocated with _Jv_AllocRawObj (see defineclass.cc), so it will
+ // be scanned. A pointer to this array is held by Class and thus
+ // seen by the collector.
char *reference_fields = (char *) _Jv_AllocRawObj (pointer_size);
char *non_reference_fields = (char *) _Jv_AllocBytes (other_size);
_Jv_ResolvedMethod *
_Jv_InterpreterEngine::do_resolve_method (_Jv_Method *method, jclass klass,
- jboolean staticp, jint vtable_index)
+ jboolean staticp)
{
int arg_count = _Jv_count_arguments (method->signature, staticp);
&result->arg_types[0],
NULL);
- result->vtable_index = vtable_index;
result->method = method;
result->klass = klass;