X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libjava%2Fprims.cc;h=a0ad08e738fb52985226b1a4cabc9b8fc4eb076f;hb=e755efce8f87ba0b194aab239570f6a0690dc88a;hp=06791d388f393e00eebe07b005ecc4aa61ddc58e;hpb=d69affc26ace1de66e37f03bc9d9afabc1bfd1a6;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libjava/prims.cc b/libjava/prims.cc index 06791d388f3..a0ad08e738f 100644 --- a/libjava/prims.cc +++ b/libjava/prims.cc @@ -25,6 +25,7 @@ details. */ #include #include #include +#include #ifdef ENABLE_JVMPI #include @@ -60,7 +61,7 @@ details. */ #include #include #include -#include +#include #ifdef USE_LTDL #include @@ -389,16 +390,15 @@ jvmpi_notify_alloc(jclass klass, jint size, jobject obj) # define jvmpi_notify_alloc(klass,size,obj) /* do nothing */ #endif -// Allocate a new object of class KLASS. SIZE is the size of the object -// to allocate. You might think this is redundant, but it isn't; some -// classes, such as String, aren't of fixed size. +// Allocate a new object of class KLASS. // First a version that assumes that we have no finalizer, and that // the class is already initialized. // If we know that JVMPI is disabled, this can be replaced by a direct call // to the allocator for the appropriate GC. jobject -_Jv_AllocObjectNoInitNoFinalizer (jclass klass, jint size) +_Jv_AllocObjectNoInitNoFinalizer (jclass klass) { + jint size = klass->size (); jobject obj = (jobject) _Jv_AllocObj (size, klass); jvmpi_notify_alloc (klass, size, obj); return obj; @@ -406,9 +406,10 @@ _Jv_AllocObjectNoInitNoFinalizer (jclass klass, jint size) // And now a version that initializes if necessary. jobject -_Jv_AllocObjectNoFinalizer (jclass klass, jint size) +_Jv_AllocObjectNoFinalizer (jclass klass) { _Jv_InitClass (klass); + jint size = klass->size (); jobject obj = (jobject) _Jv_AllocObj (size, klass); jvmpi_notify_alloc (klass, size, obj); return obj; @@ -416,10 +417,10 @@ _Jv_AllocObjectNoFinalizer (jclass klass, jint size) // And now the general version that registers a finalizer if necessary. jobject -_Jv_AllocObject (jclass klass, jint size) +_Jv_AllocObject (jclass klass) { - jobject obj = _Jv_AllocObjectNoFinalizer (klass, size); - + jobject obj = _Jv_AllocObjectNoFinalizer (klass); + // We assume that the compiler only generates calls to this routine // if there really is an interesting finalizer. // Unfortunately, we still have to the dynamic test, since there may @@ -432,14 +433,62 @@ _Jv_AllocObject (jclass klass, jint size) return obj; } +// Allocate a String, including variable length storage. +jstring +_Jv_AllocString(jsize len) +{ + using namespace java::lang; + + jsize sz = sizeof(java::lang::String) + len * sizeof(jchar); + + // We assert that for strings allocated this way, the data field + // will always point to the object itself. Thus there is no reason + // for the garbage collector to scan any of it. + // Furthermore, we're about to overwrite the string data, so + // initialization of the object is not an issue. + + // String needs no initialization, and there is no finalizer, so + // we can go directly to the collector's allocator interface. + jstring obj = (jstring) _Jv_AllocPtrFreeObj(sz, &String::class$); + + obj->data = obj; + obj->boffset = sizeof(java::lang::String); + obj->count = len; + obj->cachedHashCode = 0; + +#ifdef ENABLE_JVMPI + // Service JVMPI request. + + if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC != 0, false)) + { + JVMPI_Event event; + + event.event_type = JVMPI_EVENT_OBJECT_ALLOC; + event.env_id = NULL; + event.u.obj_alloc.arena_id = 0; + event.u.obj_alloc.class_id = (jobjectID) &String::class$; + event.u.obj_alloc.is_array = 0; + event.u.obj_alloc.size = sz; + event.u.obj_alloc.obj_id = (jobjectID) obj; + + _Jv_DisableGC (); + (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (&event); + _Jv_EnableGC (); + } +#endif + + return obj; +} + // A version of the above that assumes the object contains no pointers, // and requires no finalization. This can't happen if we need pointers // to locks. #ifdef JV_HASH_SYNCHRONIZATION jobject -_Jv_AllocPtrFreeObject (jclass klass, jint size) +_Jv_AllocPtrFreeObject (jclass klass) { _Jv_InitClass (klass); + jint size = klass->size (); jobject obj = (jobject) _Jv_AllocPtrFreeObj (size, klass); @@ -873,8 +922,10 @@ process_gcj_properties () // Null terminate the strings. while (_Jv_Environment_Properties[i].key) { - _Jv_Environment_Properties[i].key[_Jv_Environment_Properties[i].key_length] = 0; - _Jv_Environment_Properties[i++].value[_Jv_Environment_Properties[i].value_length] = 0; + property_pair *prop = &_Jv_Environment_Properties[i]; + prop->key[prop->key_length] = 0; + prop->value[prop->value_length] = 0; + i++; } } } @@ -905,6 +956,18 @@ _Jv_CreateJavaVM (void* /*vm_args*/) _Jv_InitThreads (); _Jv_InitGC (); _Jv_InitializeSyncMutex (); + +#ifdef INTERPRETER + _Jv_InitInterpreter (); +#endif + +#ifdef HANDLE_SEGV + INIT_SEGV; +#endif + +#ifdef HANDLE_FPE + INIT_FPE; +#endif /* Initialize Utf8 constants declared in jvm.h. */ void_signature = _Jv_makeUtf8Const ("()V", 3); @@ -932,15 +995,11 @@ _Jv_CreateJavaVM (void* /*vm_args*/) // initialization of ClassLoader before we start the initialization // of VMClassLoader. _Jv_InitClass (&java::lang::ClassLoader::class$); + // Once the bootstrap loader is in place, change it into a kind of // system loader, by having it read the class path. gnu::gcj::runtime::VMClassLoader::initialize(); - INIT_SEGV; -#ifdef HANDLE_FPE - INIT_FPE; -#endif - no_memory = new java::lang::OutOfMemoryError; java::lang::VMThrowable::trace_enabled = 1; @@ -956,8 +1015,7 @@ _Jv_CreateJavaVM (void* /*vm_args*/) _Jv_GCInitializeFinalizers (&::gnu::gcj::runtime::FinalizerThread::finalizerReady); // Start the GC finalizer thread. A VirtualMachineError can be - // thrown by the runtime if, say, threads aren't available. In this - // case finalizers simply won't run. + // thrown by the runtime if, say, threads aren't available. try { using namespace gnu::gcj::runtime; @@ -975,7 +1033,9 @@ void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv, bool is_jar) { +#ifndef DISABLE_MAIN_ARGS _Jv_SetArgs (argc, argv); +#endif java::lang::Runtime *runtime = NULL; @@ -997,12 +1057,12 @@ _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv, arg_vec = JvConvertArgv (argc - 1, argv + 1); #endif - using namespace gnu::gcj::runtime; + using namespace gnu::java::lang; if (klass) - main_thread = new FirstThread (klass, arg_vec); + main_thread = new MainThread (klass, arg_vec); else - main_thread = new FirstThread (JvNewStringLatin1 (name), - arg_vec, is_jar); + main_thread = new MainThread (JvNewStringLatin1 (name), + arg_vec, is_jar); } catch (java::lang::Throwable *t) {