#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
// 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;
* 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.
+ SAVE_PC();
+ 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
{
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)
+
+ if (rmeth->method->accflags & Modifier::FINAL)
{
+ // We can't rely on NULLCHECK working if the method is final.
SAVE_PC();
- throw new java::lang::NullPointerException;
- }
+ if (! sp[0].o)
+ throw_null_pointer_exception ();
- if (rmeth->vtable_index == -1)
- {
- // final methods do not appear in the vtable,
- // if it does not appear in the superclass.
+ // 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;
jclass type = field->type;
jint field_offset = field->u.boffset;
- if (field_offset > 0xffff)
- throw new java::lang::VirtualMachineError;
jobject obj = POPA();
NULLCHECK(obj);
(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 ())
if (! sp[0].o)
{
SAVE_PC();
- throw new java::lang::NullPointerException;
+ throw_null_pointer_exception ();
}
fun = (void (*)()) rmeth->method->ncode;
if (! sp[0].o)
{
SAVE_PC();
- throw new java::lang::NullPointerException;
+ throw_null_pointer_exception ();
}
fun = (void (*)()) rmeth->method->ncode;
}
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;