aboutsummaryrefslogtreecommitdiff
path: root/libjava/link.cc
diff options
context:
space:
mode:
authorAlexandre Oliva <aoliva@redhat.com>2007-03-07 07:27:25 +0000
committerAlexandre Oliva <aoliva@gcc.gnu.org>2007-03-07 07:27:25 +0000
commit18fa3240db054b98ef9464cbcedb186d819217fd (patch)
tree65dc1e16680788d96a4fb13f1406c83419164f7c /libjava/link.cc
parentdd77833100a12f219e7278685059dd82196c78f4 (diff)
downloadgcc-18fa3240db054b98ef9464cbcedb186d819217fd.zip
gcc-18fa3240db054b98ef9464cbcedb186d819217fd.tar.gz
gcc-18fa3240db054b98ef9464cbcedb186d819217fd.tar.bz2
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog: * include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New. (ffi_prep_closure_loc): New. (ffi_prep_raw_closure_loc): New. (ffi_prep_java_raw_closure_loc): New. * src/closures.c: New file. * src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment): Replace sflags with exec_offset. [FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset, sub_segment_exec_offset): New macros. (get_segment_flags, set_segment_flags, check_segment_merge): New macros. (is_mmapped_segment, is_extern_segment): Use get_segment_flags. (add_segment, sys_alloc, create_mspace, create_mspace_with_base, destroy_mspace): Use new macros. (sys_alloc): Silence warning. * Makefile.am (libffi_la_SOURCES): Add src/closures.c. * Makefile.in: Rebuilt. * src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in terms of ffi_prep_closure_loc. * src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted from... (ffi_prep_raw_closure): ... this. Re-implement in terms of the renamed version. * src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and adjusted from... (ffi_prep_java_raw_closure): ... this. Re-implement in terms of the renamed version. * src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from (ffi_prep_closure): ... this. * src/pa/ffi.c: Likewise. * src/cris/ffi.c: Likewise. Adjust. * src/frv/ffi.c: Likewise. * src/ia64/ffi.c: Likewise. * src/mips/ffi.c: Likewise. * src/powerpc/ffi_darwin.c: Likewise. * src/s390/ffi.c: Likewise. * src/sh/ffi.c: Likewise. * src/sh64/ffi.c: Likewise. * src/sparc/ffi.c: Likewise. * src/x86/ffi64.c: Likewise. * src/x86/ffi.c: Likewise. (FFI_INIT_TRAMPOLINE): Adjust. (ffi_prep_raw_closure_loc): Renamed and adjusted from... (ffi_prep_raw_closure): ... this. * src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from (ffi_prep_closure): ... this. (flush_icache): Adjust. boehm-gc/ChangeLog: * include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New. (GC_register_finalizer_unreachable): Declare. (GC_debug_register_finalizer_unreachable): Declare. * finalize.c (GC_unreachable_finalize_mark_proc): New. (GC_register_finalizer_unreachable): New. (GC_finalize): Handle it. * dbg_mlc.c (GC_debug_register_finalizer_unreachable): New. (GC_debug_register_finalizer_no_order): Fix whitespace. libjava/ChangeLog: * include/jvm.h (_Jv_ClosureListFinalizer): New. (_Jv_Linker::create_error_method): Adjust. * boehm.cc (_Jv_ClosureListFinalizer): New. * nogc.cc (_Jv_ClosureListFinalizer): New. * java/lang/Class.h (class _Jv_ClosureList): New. (class java::lang::Class): Declare it as friend. * java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New. (_Jv_ClosureList::registerClousure): New. * include/execution.h (_Jv_ExecutionEngine): Add get_closure_list. (_Jv_CompiledEngine::do_get_closure_list): New. (_Jv_CompiledEngine::_Jv_CompiledEngine): Use it. (_Jv_IndirectCompiledClass): Add closures. (_Jv_IndirectCompiledEngine::get_aux_info): New. (_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use it. (_Jv_IndirectCompiledEngine::do_get_closure_list): New. (_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it. (_Jv_InterpreterEngine::do_get_closure_list): Declare. (_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it. * interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants. (node_closure): Add closure list. (_Jv_InterpMethod::ncode): Add jclass argument. Use ffi_closure_alloc and the separate code pointer. Register the closure for finalization. (_Jv_JNIMethod::ncode): Likewise. (_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode. (_Jv_InterpreterEngine::do_get_closure_list): New. * include/java-interp.h (_Jv_InterpMethod::ncode): Adjust. (_Jv_InterpClass): Add closures field. (_Jv_JNIMethod::ncode): Adjust. * defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust. (_Jv_ClassReader::handleMethodsEnd): Likewise. * link.cc (struct method_closure): Add closure list. (_Jv_Linker::create_error_method): Add jclass argument. Use ffi_closure_alloc and the separate code pointer. Register the closure for finalization. (_Jv_Linker::link_symbol_table): Remove outdated comment about sharing of otable and atable. Adjust. * java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure list. (ncode): Add jclass argument. Use ffi_closure_alloc and the separate code pointer. Register the closure for finalization. (java::lang::reflect::VMProxy::generateProxyClass): Adjust. * testsuite/libjava.jar/TestClosureGC.java: New. * testsuite/libjava.jar/TestClosureGC.out: New. * testsuite/libjava.jar/TestClosureGC.xfail: New. * testsuite/libjava.jar/TestClosureGC.jar: New. From-SVN: r122652
Diffstat (limited to 'libjava/link.cc')
-rw-r--r--libjava/link.cc35
1 files changed, 23 insertions, 12 deletions
diff --git a/libjava/link.cc b/libjava/link.cc
index 006676c..4ea548e 100644
--- a/libjava/link.cc
+++ b/libjava/link.cc
@@ -1022,15 +1022,17 @@ struct method_closure
// be the same as the address of the overall structure. This is due
// to disabling interior pointers in the GC.
ffi_closure closure;
+ _Jv_ClosureList list;
ffi_cif cif;
ffi_type *arg_types[1];
};
void *
-_Jv_Linker::create_error_method (_Jv_Utf8Const *class_name)
+_Jv_Linker::create_error_method (_Jv_Utf8Const *class_name, jclass klass)
{
+ void *code;
method_closure *closure
- = (method_closure *) _Jv_AllocBytes(sizeof (method_closure));
+ = (method_closure *)ffi_closure_alloc (sizeof (method_closure), &code);
closure->arg_types[0] = &ffi_type_void;
@@ -1042,13 +1044,18 @@ _Jv_Linker::create_error_method (_Jv_Utf8Const *class_name)
1,
&ffi_type_void,
closure->arg_types) == FFI_OK
- && ffi_prep_closure (&closure->closure,
- &closure->cif,
- _Jv_ThrowNoClassDefFoundErrorTrampoline,
- class_name) == FFI_OK)
- return &closure->closure;
+ && ffi_prep_closure_loc (&closure->closure,
+ &closure->cif,
+ _Jv_ThrowNoClassDefFoundErrorTrampoline,
+ class_name,
+ code) == FFI_OK)
+ {
+ closure->list.registerClosure (klass, closure);
+ return code;
+ }
else
{
+ ffi_closure_free (closure);
java::lang::StringBuffer *buffer = new java::lang::StringBuffer();
buffer->append(JvNewStringLatin1("Error setting up FFI closure"
" for static method of"
@@ -1059,7 +1066,7 @@ _Jv_Linker::create_error_method (_Jv_Utf8Const *class_name)
}
#else
void *
-_Jv_Linker::create_error_method (_Jv_Utf8Const *)
+_Jv_Linker::create_error_method (_Jv_Utf8Const *, jclass)
{
// Codepath for platforms which do not support (or want) libffi.
// You have to accept that it is impossible to provide the name
@@ -1090,8 +1097,6 @@ static bool debug_link = false;
// at the corresponding position in the virtual method offset table
// (klass->otable).
-// The same otable and atable may be shared by many classes.
-
// This must be called while holding the class lock.
void
@@ -1242,13 +1247,15 @@ _Jv_Linker::link_symbol_table (jclass klass)
// NullPointerException
klass->atable->addresses[index] = NULL;
+ bool use_error_method = false;
+
// If the target class is missing we prepare a function call
// that throws a NoClassDefFoundError and store the address of
// that newly prepared method in the atable. The user can run
// code in classes where the missing class is part of the
// execution environment as long as it is never referenced.
if (target_class == NULL)
- klass->atable->addresses[index] = create_error_method(sym.class_name);
+ use_error_method = true;
// We're looking for a static field or a static method, and we
// can tell which is needed by looking at the signature.
else if (signature->first() == '(' && signature->len() >= 2)
@@ -1296,12 +1303,16 @@ _Jv_Linker::link_symbol_table (jclass klass)
}
}
else
+ use_error_method = true;
+
+ if (use_error_method)
klass->atable->addresses[index]
- = create_error_method(sym.class_name);
+ = create_error_method(sym.class_name, klass);
continue;
}
+
// Try fields only if the target class exists.
if (target_class != NULL)
{