From 976731ee6e809f1201abbed7e85717bda0025fb1 Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Fri, 13 Jul 2007 14:07:16 +0000 Subject: [PATCH] [multiple changes] 2007-07-13 Andrew Haley * libgcj.ver: Add __gcj_personality_sj0. * testsuite/libjava.jvmti/jvmti-interp.exp: Likewise. * testsuite/libjava.jni/jni.exp: Use -fdollars-in-identifiers. * testsuite/libjava.jni/cni.exp: Use -fdollars-in-identifiers. * testsuite/libjava.jvmti/jvmti.exp (gcj_jvmti_compile_cxx_to_o): Likewise. * gnu/classpath/natVMStackWalker.cc (getCallingClassLoader): Check klass is non-null. * java/lang/reflect/natField.cc (getAddr): Call _Jv_StackTrace::GetCallingClass only if CALLER is non-null. * java/lang/reflect/natVMProxy.cc (run_proxy): Use _Jv_getFieldInternal to get field proxyClass.m. (_Jv_getFieldInternal): New function. 2007-07-11 Andrew Haley * configure.host (arm*-linux-gnu): New. * sysdep/arm/locks.h: New. From-SVN: r126622 --- libjava/ChangeLog | 22 ++++++ libjava/configure.host | 4 + libjava/gnu/classpath/natVMStackWalker.cc | 13 ++- libjava/headers.txt | 2 + libjava/java/lang/reflect/Field.h | 2 + libjava/java/lang/reflect/natField.cc | 8 +- libjava/java/lang/reflect/natVMProxy.cc | 12 ++- libjava/libgcj.ver | 2 +- libjava/sysdep/arm/locks.h | 79 +++++++++++++++++++ libjava/testsuite/libjava.cni/cni.exp | 2 +- libjava/testsuite/libjava.jni/jni.exp | 4 +- .../testsuite/libjava.jvmti/jvmti-interp.exp | 2 +- libjava/testsuite/libjava.jvmti/jvmti.exp | 4 +- 13 files changed, 139 insertions(+), 17 deletions(-) create mode 100644 libjava/sysdep/arm/locks.h diff --git a/libjava/ChangeLog b/libjava/ChangeLog index a51629f4424..bf8c193d90b 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,25 @@ +2007-07-13 Andrew Haley + + * libgcj.ver: Add __gcj_personality_sj0. + + * testsuite/libjava.jvmti/jvmti-interp.exp: Likewise. + * testsuite/libjava.jni/jni.exp: Use -fdollars-in-identifiers. + * testsuite/libjava.jni/cni.exp: Use -fdollars-in-identifiers. + * testsuite/libjava.jvmti/jvmti.exp (gcj_jvmti_compile_cxx_to_o): Likewise. + + * gnu/classpath/natVMStackWalker.cc (getCallingClassLoader): Check + klass is non-null. + * java/lang/reflect/natField.cc (getAddr): Call + _Jv_StackTrace::GetCallingClass only if CALLER is non-null. + * java/lang/reflect/natVMProxy.cc (run_proxy): Use + _Jv_getFieldInternal to get field proxyClass.m. + (_Jv_getFieldInternal): New function. + +2007-07-11 Andrew Haley + + * configure.host (arm*-linux-gnu): New. + * sysdep/arm/locks.h: New. + 2007-07-13 Roger Sayle * java/lang/natPosixProcess.cc: Include before diff --git a/libjava/configure.host b/libjava/configure.host index 3c15abcb510..c32e714ea65 100644 --- a/libjava/configure.host +++ b/libjava/configure.host @@ -82,6 +82,10 @@ case "${host}" in enable_getenv_properties_default=no enable_main_args_default=no ;; + arm*-linux-gnu) + libgcj_interpreter=yes + sysdeps_dir=arm + ;; mips-tx39-*|mipstx39-unknown-*) libgcj_flags="${libgcj_flags} -G 0" LDFLAGS="$LDFLAGS -Tjmr3904dram.ld" diff --git a/libjava/gnu/classpath/natVMStackWalker.cc b/libjava/gnu/classpath/natVMStackWalker.cc index f7eb8832f4c..1b336cad063 100644 --- a/libjava/gnu/classpath/natVMStackWalker.cc +++ b/libjava/gnu/classpath/natVMStackWalker.cc @@ -80,15 +80,22 @@ gnu::classpath::VMStackWalker::getClassLoader(::java::lang::Class *c) gnu::classpath::VMStackWalker::getCallingClassLoader(void) { _Jv_InitClass (&::gnu::classpath::VMStackWalker::class$); - return - _Jv_StackTrace::GetStackWalkerCallingClass ()->getClassLoaderInternal (); + jclass klass = _Jv_StackTrace::GetStackWalkerCallingClass (); + if (klass) + return klass->getClassLoaderInternal (); + else + return NULL; } ::java::lang::ClassLoader * gnu::classpath::VMStackWalker::getCallingClassLoader(::gnu::gcj::RawData *pc) { _Jv_InitClass (&::gnu::classpath::VMStackWalker::class$); - return GET_CALLING_CLASS(pc)->getClassLoaderInternal (); + jclass klass = GET_CALLING_CLASS(pc); + if (klass) + return klass->getClassLoaderInternal (); + else + return NULL; } ::java::lang::ClassLoader * diff --git a/libjava/headers.txt b/libjava/headers.txt index aad3fdd60c1..d28d4090e6e 100644 --- a/libjava/headers.txt +++ b/libjava/headers.txt @@ -49,9 +49,11 @@ friend class java::lang::Class; class java/lang/reflect/Field prepend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *); prepend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv*, jclass, jfieldID, jboolean); +prepend jobject _Jv_getFieldInternal (java::lang::reflect::Field f, jclass c, jobject o); friend jfieldID (::_Jv_FromReflectedField) (java::lang::reflect::Field *); friend jobject (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv*, jclass, jfieldID, jboolean); friend class java::lang::Class; +friend jobject (::_Jv_getFieldInternal) (java::lang::reflect::Field f, jclass c, jobject o); class java/lang/reflect/Method prepend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *); diff --git a/libjava/java/lang/reflect/Field.h b/libjava/java/lang/reflect/Field.h index 3e39fb2bad1..0af95652def 100644 --- a/libjava/java/lang/reflect/Field.h +++ b/libjava/java/lang/reflect/Field.h @@ -12,6 +12,7 @@ jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *); jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv*, jclass, jfieldID, jboolean); +jobject _Jv_getFieldInternal (java::lang::reflect::Field *f, jclass c, jobject o); class java::lang::reflect::Field : public ::java::lang::reflect::AccessibleObject { @@ -91,6 +92,7 @@ public: friend jfieldID (::_Jv_FromReflectedField) (java::lang::reflect::Field *); friend jobject (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv*, jclass, jfieldID, jboolean); friend class java::lang::Class; + friend jobject (::_Jv_getFieldInternal) (java::lang::reflect::Field *f, jclass c, jobject o); }; #endif // __java_lang_reflect_Field__ diff --git a/libjava/java/lang/reflect/natField.cc b/libjava/java/lang/reflect/natField.cc index b107ab851b7..734f653168b 100644 --- a/libjava/java/lang/reflect/natField.cc +++ b/libjava/java/lang/reflect/natField.cc @@ -74,11 +74,6 @@ static void* getAddr (java::lang::reflect::Field* field, jclass caller, jobject obj, jboolean checkFinal) { - // FIXME: we know CALLER is NULL here. At one point we planned to - // have the compiler insert the caller as a hidden argument in some - // calls. However, we never implemented that, so we have to find - // the caller by hand instead. - using namespace java::lang::reflect; jfieldID fld = _Jv_FromReflectedField (field); @@ -97,7 +92,8 @@ getAddr (java::lang::reflect::Field* field, jclass caller, jobject obj, // Check accessibility, if required. if (! (Modifier::isPublic (flags) || field->isAccessible())) { - caller = _Jv_StackTrace::GetCallingClass (&Field::class$); + if (! caller) + caller = _Jv_StackTrace::GetCallingClass (&Field::class$); if (! _Jv_CheckAccess (caller, field->getDeclaringClass(), flags)) throw new java::lang::IllegalAccessException; } diff --git a/libjava/java/lang/reflect/natVMProxy.cc b/libjava/java/lang/reflect/natVMProxy.cc index e5f8fbe52aa..1d9a3c6a551 100644 --- a/libjava/java/lang/reflect/natVMProxy.cc +++ b/libjava/java/lang/reflect/natVMProxy.cc @@ -299,6 +299,15 @@ unbox (jobject o, jclass klass, void *rvalue, FFI_TYPE type) JvFail ("Bad ffi type in proxy"); } +// _Jv_getFieldInternal is declared as a friend of reflect.Field in +// libjava/headers.txt. This gives us a way to call the private +// method Field.get (Class caller, Object obj). +extern inline jobject +_Jv_getFieldInternal (java::lang::reflect::Field *f, jclass c, jobject o) +{ + return f->get(c, o); +} + // run_proxy is the entry point for all proxy methods. It boxes up // all the arguments and then invokes the invocation handler's invoke() // method. Exceptions are caught and propagated. @@ -340,7 +349,8 @@ run_proxy (ffi_cif *cif, // difference. We'd still have to save the method array because // ncode structs are not scanned by the gc. Field *f = proxyClass->getDeclaredField (JvNewStringLatin1 ("m")); - JArray *methods = (JArray*)f->get (NULL); + JArray *methods + = (JArray*)_Jv_getFieldInternal (f, proxyClass, NULL); Method *meth = elements(methods)[self->method_index]; JArray *parameter_types = meth->internalGetParameterTypes (); diff --git a/libjava/libgcj.ver b/libjava/libgcj.ver index 344600c8206..d2d189b5249 100644 --- a/libjava/libgcj.ver +++ b/libjava/libgcj.ver @@ -2,6 +2,6 @@ # symbols in libgcj.so. { - global: Jv*; _Jv_*; __gcj_personality_v0; _Z*; + global: Jv*; _Jv_*; __gcj_personality_v0; __gcj_personality_sj0; _Z*; local: *; }; diff --git a/libjava/sysdep/arm/locks.h b/libjava/sysdep/arm/locks.h new file mode 100644 index 00000000000..1f7763de3f0 --- /dev/null +++ b/libjava/sysdep/arm/locks.h @@ -0,0 +1,79 @@ +// locks.h - Thread synchronization primitives. ARM implementation. + +/* Copyright (C) 2007 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#ifndef __SYSDEP_LOCKS_H__ +#define __SYSDEP_LOCKS_H__ + +typedef size_t obj_addr_t; /* Integer type big enough for object */ + /* address. */ + +/* Atomic compare and exchange. These sequences are not actually + atomic; there is a race if *ADDR != OLD_VAL and we are preempted + between the two swaps. However, they are very close to atomic, and + are the best that a pre-ARMv6 implementation can do without + operating system support. LinuxThreads has been using these + sequences for many years. */ + +inline static bool +compare_and_swap(volatile obj_addr_t *addr, + obj_addr_t old_val, + obj_addr_t new_val) +{ + volatile obj_addr_t result, tmp; + __asm__ ("\n" + "0: ldr %[tmp],[%[addr]]\n" + " cmp %[tmp],%[old_val]\n" + " movne %[result],#0\n" + " bne 1f\n" + " swp %[result],%[new_val],[%[addr]]\n" + " cmp %[tmp],%[result]\n" + " swpne %[tmp],%[result],[%[addr]]\n" + " bne 0b\n" + " mov %[result],#1\n" + "1:" + : [result] "=&r" (result), [tmp] "=&r" (tmp) + : [addr] "r" (addr), [new_val] "r" (new_val), [old_val] "r" (old_val) + : "cc", "memory"); + + return result; +} + +inline static void +release_set(volatile obj_addr_t *addr, obj_addr_t new_val) +{ + __asm__ __volatile__("" : : : "memory"); + *(addr) = new_val; +} + +inline static bool +compare_and_swap_release(volatile obj_addr_t *addr, + obj_addr_t old, + obj_addr_t new_val) +{ + return compare_and_swap(addr, old, new_val); +} + +// Ensure that subsequent instructions do not execute on stale +// data that was loaded from memory before the barrier. +inline static void +read_barrier() +{ + __asm__ __volatile__("" : : : "memory"); +} + +// Ensure that prior stores to memory are completed with respect to other +// processors. +inline static void +write_barrier() +{ + __asm__ __volatile__("" : : : "memory"); +} + +#endif diff --git a/libjava/testsuite/libjava.cni/cni.exp b/libjava/testsuite/libjava.cni/cni.exp index 61fee3b0200..aec16b9330b 100644 --- a/libjava/testsuite/libjava.cni/cni.exp +++ b/libjava/testsuite/libjava.cni/cni.exp @@ -10,7 +10,7 @@ proc gcj_cni_compile_cxx_to_o {file {options {}}} { set oname ${name}.o # Find the generated header. - lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir" + lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir -fdollars-in-identifiers" # Find libgcj headers. lappend options "additional_flags=-I$srcdir/.." diff --git a/libjava/testsuite/libjava.jni/jni.exp b/libjava/testsuite/libjava.jni/jni.exp index 1fff2b2f019..ab22c23f68a 100644 --- a/libjava/testsuite/libjava.jni/jni.exp +++ b/libjava/testsuite/libjava.jni/jni.exp @@ -31,7 +31,7 @@ proc gcj_jni_compile_c_to_so {file {options {}}} { lappend options "additional_flags=${so_flag} -fPIC" # Find the generated header. - lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir" + lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir -fdollars-in-identifiers" # Ensure that the generated header has correct prototypes. set cfile [file rootname $file].c @@ -219,7 +219,7 @@ proc gcj_jni_invocation_compile_c_to_binary {file {options {}}} { lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir" # Find jni.h and jni_md.h. - lappend options "additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include" + lappend options "additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include -fdollars-in-identifiers" # Append C++ options lappend options "additional_flags=$options_cxx" diff --git a/libjava/testsuite/libjava.jvmti/jvmti-interp.exp b/libjava/testsuite/libjava.jvmti/jvmti-interp.exp index bf0662b00d0..68b1fc8c177 100644 --- a/libjava/testsuite/libjava.jvmti/jvmti-interp.exp +++ b/libjava/testsuite/libjava.jvmti/jvmti-interp.exp @@ -47,7 +47,7 @@ proc gcj_jni_compile_c_to_so {file {options {}}} { # Find jni.h and jni_md.h. lappend options "additional_flags=-I$srcdir/../include \ - -I$srcdir/../classpath/include" + -I$srcdir/../classpath/include -fdollars-in-identifiers" # Append C++ options lappend options "additional_flags=$options_cxx" diff --git a/libjava/testsuite/libjava.jvmti/jvmti.exp b/libjava/testsuite/libjava.jvmti/jvmti.exp index c69fd2bc0f0..578eeb1ef3f 100644 --- a/libjava/testsuite/libjava.jvmti/jvmti.exp +++ b/libjava/testsuite/libjava.jvmti/jvmti.exp @@ -11,11 +11,11 @@ proc gcj_jvmti_compile_cxx_to_o {file {options {}}} { set oname ${name}.o # Find the generated header. - lappend options "additional_flags=-g -I. -I.." + lappend options "additional_flags=-g -I. -I.. -fdollars-in-identifiers" # Find libgcj headers. lappend options "additional_flags=-I$srcdir/.." # Find jvmti.h, jvmti_md.h, jvmti-int.h, jvm.h requirements - lappend options "additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include -I$objdir/../include -I$objdir/../../boehm-gc/include" + lappend options "additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include -I$objdir/../include -I$objdir/../../boehm-gc/include " set x [libjava_prune_warnings \ [target_compile $file $oname object $options]]