/* src/vm/builtin.c - functions for unsupported operations
- Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
#include "native/llni.h"
#include "threads/lock-common.h"
-#include "threads/threads-common.h"
+#include "threads/thread.h"
#include "toolbox/logging.h"
#include "toolbox/util.h"
#include "vm/exceptions.h"
#include "vm/global.h"
#include "vm/initialize.h"
-#include "vm/primitive.h"
+#include "vm/primitive.hpp"
#include "vm/stringlocal.h"
#include "vm/jit/asmpart.h"
static bool builtintable_init(void)
{
descriptor_pool *descpool;
- s4 dumpsize;
builtintable_entry *bte;
methodinfo *m;
+ int32_t dumpmarker;
/* mark start of dump memory area */
- dumpsize = dump_size();
+ DMARKER;
/* create a new descriptor pool */
if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
/* release dump area */
- dump_release(dumpsize);
+ DRELEASE;
return false;
}
bte->descriptor = utf_new_char(bte->cdescriptor);
if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
- dump_release(dumpsize);
+ DRELEASE;
return false;
}
}
bte->descriptor = utf_new_char(bte->cdescriptor);
if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
- dump_release(dumpsize);
+ DRELEASE;
return false;
}
}
/* release dump area */
- dump_release(dumpsize);
+ DRELEASE;
return true;
}
bool builtin_init(void)
{
+ TRACESUBSYSTEMINITIALIZATION("builtin_init");
+
/* initialize the builtin tables */
if (!builtintable_init())
*******************************************************************************/
-s4 builtin_instanceof(java_handle_t *o, classinfo *class)
+bool builtin_instanceof(java_handle_t *o, classinfo *c)
{
- classinfo *c;
+ classinfo *oc;
if (o == NULL)
return 0;
- LLNI_class_get(o, c);
+ LLNI_class_get(o, oc);
- return class_isanysubclass(c, class);
+ return class_isanysubclass(oc, c);
}
*******************************************************************************/
-s4 builtin_checkcast(java_handle_t *o, classinfo *class)
+bool builtin_checkcast(java_handle_t *o, classinfo *c)
{
- classinfo *c;
+ classinfo *oc;
if (o == NULL)
return 1;
- LLNI_class_get(o, c);
+ LLNI_class_get(o, oc);
- if (class_isanysubclass(c, class))
+ if (class_isanysubclass(oc, c))
return 1;
return 0;
*******************************************************************************/
-static s4 builtin_descriptorscompatible(arraydescriptor *desc,
- arraydescriptor *target)
+static bool builtin_descriptorscompatible(arraydescriptor *desc, arraydescriptor *target)
{
if (desc == target)
return 1;
/* {both arrays are arrays of references} */
if (desc->dimension == target->dimension) {
+ if (!desc->elementvftbl)
+ return 0;
/* an array which contains elements of interface types is
allowed to be casted to Object (JOWENN)*/
(target->elementvftbl->baseval == 1))
return 1;
- return class_isanysubclass(desc->elementvftbl->class,
- target->elementvftbl->class);
+ return class_isanysubclass(desc->elementvftbl->clazz,
+ target->elementvftbl->clazz);
}
if (desc->dimension < target->dimension)
/* {desc has higher dimension than target} */
return class_isanysubclass(pseudo_class_Arraystub,
- target->elementvftbl->class);
+ target->elementvftbl->clazz);
}
*******************************************************************************/
-s4 builtin_fast_arraycheckcast(java_object_t *o, classinfo *targetclass)
+bool builtin_fast_arraycheckcast(java_object_t *o, classinfo *targetclass)
{
arraydescriptor *desc;
*******************************************************************************/
-s4 builtin_fast_arrayinstanceof(java_object_t *o, classinfo *targetclass)
+bool builtin_fast_arrayinstanceof(java_object_t *o, classinfo *targetclass)
{
if (o == NULL)
return 0;
*******************************************************************************/
-s4 builtin_arrayinstanceof(java_handle_t *h, classinfo *targetclass)
+bool builtin_arrayinstanceof(java_handle_t *h, classinfo *targetclass)
{
- s4 result;
+ bool result;
LLNI_CRITICAL_START;
*******************************************************************************/
-s4 builtin_canstore(java_handle_objectarray_t *oa, java_handle_t *o)
+bool builtin_canstore(java_handle_objectarray_t *oa, java_handle_t *o)
{
- int result;
+ bool result;
LLNI_CRITICAL_START;
*******************************************************************************/
-s4 builtin_fast_canstore(java_objectarray_t *oa, java_object_t *o)
+bool builtin_fast_canstore(java_objectarray_t *oa, java_object_t *o)
{
arraydescriptor *desc;
arraydescriptor *valuedesc;
vftbl_t *valuevftbl;
int32_t baseval;
uint32_t diffval;
- int result;
+ bool result;
if (o == NULL)
return 1;
/* This is an optimized version where a is guaranteed to be one-dimensional */
-s4 builtin_fast_canstore_onedim(java_objectarray_t *a, java_object_t *o)
+bool builtin_fast_canstore_onedim(java_objectarray_t *a, java_object_t *o)
{
arraydescriptor *desc;
vftbl_t *elementvftbl;
vftbl_t *valuevftbl;
int32_t baseval;
uint32_t diffval;
- int result;
+ bool result;
if (o == NULL)
return 1;
/* This is an optimized version where a is guaranteed to be a
* one-dimensional array of a class type */
-s4 builtin_fast_canstore_onedim_class(java_objectarray_t *a, java_object_t *o)
+bool builtin_fast_canstore_onedim_class(java_objectarray_t *a, java_object_t *o)
{
vftbl_t *elementvftbl;
vftbl_t *valuevftbl;
uint32_t diffval;
- int result;
+ bool result;
if (o == NULL)
return 1;
return o;
}
+#if defined(ENABLE_ESCAPE_REASON)
+java_handle_t *builtin_escape_reason_new(classinfo *c) {
+ print_escape_reasons();
+ return builtin_java_new(c);
+}
+#endif
+
+#if defined(ENABLE_TLH)
+java_handle_t *builtin_tlh_new(classinfo *c)
+{
+ java_handle_t *o;
+#if defined(ENABLE_RT_TIMING)
+ struct timespec time_start, time_end;
+#endif
+#if defined(ENABLE_CYCLES_STATS)
+ u8 cycles_start, cycles_end;
+#endif
+
+ RT_TIMING_GET_TIME(time_start);
+ CYCLES_STATS_GET(cycles_start);
+
+ /* is the class loaded */
+
+ assert(c->state & CLASS_LOADED);
+
+ /* check if we can instantiate this class */
+
+ if (c->flags & ACC_ABSTRACT) {
+ exceptions_throw_instantiationerror(c);
+ return NULL;
+ }
+
+ /* is the class linked */
+
+ if (!(c->state & CLASS_LINKED))
+ if (!link_class(c))
+ return NULL;
+
+ if (!(c->state & CLASS_INITIALIZED)) {
+#if !defined(NDEBUG)
+ if (initverbose)
+ log_message_class("Initialize class (from builtin_new): ", c);
+#endif
+
+ if (!initialize_class(c))
+ return NULL;
+ }
+
+ /*
+ o = tlh_alloc(&(THREADOBJECT->tlh), c->instancesize);
+ */
+ o = NULL;
+
+ if (o == NULL) {
+ o = heap_alloc(c->instancesize, c->flags & ACC_CLASS_HAS_POINTERS,
+ c->finalizer, true);
+ }
+
+ if (!o)
+ return NULL;
+
+#if !defined(ENABLE_GC_CACAO) && defined(ENABLE_HANDLES)
+ /* XXX this is only a dirty hack to make Boehm work with handles */
+
+ o = LLNI_WRAP((java_object_t *) o);
+#endif
+
+ LLNI_vftbl_direct(o) = c->vftbl;
+
+#if defined(ENABLE_THREADS)
+ lock_init_object_lock(LLNI_DIRECT(o));
+#endif
+
+ CYCLES_STATS_GET(cycles_end);
+ RT_TIMING_GET_TIME(time_end);
+
+/*
+ CYCLES_STATS_COUNT(builtin_new,cycles_end - cycles_start);
+ RT_TIMING_TIME_DIFF(time_start, time_end, RT_TIMING_NEW_OBJECT);
+*/
+
+ return o;
+#endif
+}
/* builtin_java_new ************************************************************
*******************************************************************************/
-java_handle_t *builtin_newarray(s4 size, classinfo *arrayclass)
+java_handle_t *builtin_newarray(int32_t size, classinfo *arrayclass)
{
arraydescriptor *desc;
s4 dataoffset;
*******************************************************************************/
-java_handle_t *builtin_java_newarray(s4 size, java_handle_t *arrayclazz)
+java_handle_t *builtin_java_newarray(int32_t size, java_handle_t *arrayclazz)
{
return builtin_newarray(size, LLNI_classinfo_unwrap(arrayclazz));
}
*******************************************************************************/
-java_handle_objectarray_t *builtin_anewarray(s4 size, classinfo *componentclass)
+java_handle_objectarray_t *builtin_anewarray(int32_t size, classinfo *componentclass)
{
classinfo *arrayclass;
*******************************************************************************/
#define BUILTIN_NEWARRAY_TYPE(type, arraytype) \
-java_handle_##type##array_t *builtin_newarray_##type(s4 size) \
+java_handle_##type##array_t *builtin_newarray_##type(int32_t size) \
{ \
return (java_handle_##type##array_t *) \
builtin_newarray(size, primitivetype_table[arraytype].arrayclass); \
/* get the class of the components to create */
- componentclass = arrayclass->vftbl->arraydesc->componentvftbl->class;
+ componentclass = arrayclass->vftbl->arraydesc->componentvftbl->clazz;
/* The verifier guarantees that the dimension count is in the range. */
return;
}
- /* we try to throw exception with the same message as SUN does */
+ // Check if offsets and length are positive.
+ if ((srcStart < 0) || (destStart < 0) || (len < 0)) {
+ exceptions_throw_arrayindexoutofboundsexception();
+ return;
+ }
- if ((len < 0) || (srcStart < 0) || (destStart < 0) ||
- (srcStart + len < 0) || (srcStart + len > LLNI_array_size(src)) ||
- (destStart + len < 0) || (destStart + len > LLNI_array_size(dest))) {
+ // Check if ranges are valid.
+ if ((((uint32_t) srcStart + (uint32_t) len) > (uint32_t) LLNI_array_size(src)) ||
+ (((uint32_t) destStart + (uint32_t) len) > (uint32_t) LLNI_array_size(dest))) {
exceptions_throw_arrayindexoutofboundsexception();
return;
}
+ // Special case.
+ if (len == 0) {
+ return;
+ }
+
if (sdesc->componentvftbl == ddesc->componentvftbl) {
/* We copy primitive values or references of exactly the same type */