natVMClassLoader.cc (getSystemClassLoaderInternal): Updated for name change.

* java/lang/natVMClassLoader.cc (getSystemClassLoaderInternal):
	Updated for name change.
	(nativeFindClass): New method.
	(loadClass): Use nativeFindClass.
	* java/lang/natClassLoader.cc (_Jv_FindClass): Use single-argument
	form of loadClass.
	* java/lang/VMClassLoader.java (tried_libraries, lib_control,
	LIB_FULL, LIB_CACHE, LIB_NEVER): New fields from old
	VMClassLoader.
	(initialize): New method.
	(nativeFindClass): Declare.
	* gnu/gcj/runtime/natVMClassLoader.cc: Removed.
	* gnu/gcj/runtime/VMClassLoader.java: Removed.
	* gnu/gcj/runtime/ExtensionClassLoader.java: Renamed from
	VMClassLoader.java.
	(definePackageForNative): Removed.
	(tried_libraries, LIB_CACHE, LIB_FULL, LIB_NEVER, lib_control):
	Moved to VMClassLoader.java.
	* prims.cc (_Jv_CreateJavaVM): Updated for renaming.
	* Makefile.am (gnu/gcj/runtime/ExtensionClassLoader.h): Renamed.
	(ordinary_java_source_files): Added ExtensionClassLoader.java,
	removed VMClassLoader.java.
	(nat_source_files): Removed natVMClassLoader.cc.

From-SVN: r97414
This commit is contained in:
Tom Tromey
2005-04-01 19:19:13 +00:00
committed by Tom Tromey
parent 35913faefb
commit ef87438639
10 changed files with 194 additions and 206 deletions
@@ -0,0 +1,40 @@
/* Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 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. */
/* Author: Kresten Krab Thorup <krab@gnu.org> */
package gnu.gcj.runtime;
import java.net.URL;
// The extension loader for libgcj. Class loader bootstrap is a bit
// tricky, see prims.cc and SystemClassLoader for some details.
public final class ExtensionClassLoader extends HelperClassLoader
{
private ExtensionClassLoader ()
{
}
private void init()
{
addDirectoriesFromProperty("java.ext.dirs");
}
// This can be package-private because we only call it from native
// code during startup.
static void initialize ()
{
instance.init();
system_instance.init();
}
// The only ExtensionClassLoader that can exist.
static ExtensionClassLoader instance = new ExtensionClassLoader();
// The system class loader.
static SystemClassLoader system_instance = new SystemClassLoader(instance);
}
@@ -1,94 +0,0 @@
/* Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 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. */
/* Author: Kresten Krab Thorup <krab@gnu.org> */
package gnu.gcj.runtime;
import java.net.URL;
import java.util.HashSet;
// Despite its name, this class is really the extension loader for
// libgcj. Class loader bootstrap is a bit tricky, see prims.cc and
// SystemClassLoader for some details.
public final class VMClassLoader extends HelperClassLoader
{
private VMClassLoader ()
{
String p
= System.getProperty ("gnu.gcj.runtime.VMClassLoader.library_control",
"");
if ("never".equals(p))
lib_control = LIB_NEVER;
else if ("cache".equals(p))
lib_control = LIB_CACHE;
else if ("full".equals(p))
lib_control = LIB_FULL;
else
lib_control = LIB_CACHE;
}
private void init()
{
addDirectoriesFromProperty("java.ext.dirs");
}
/** This is overridden to search the internal hash table, which
* will only search existing linked-in classes. This will make
* the default implementation of loadClass (in ClassLoader) work right.
* The implementation of this method is in
* gnu/gcj/runtime/natVMClassLoader.cc.
*/
protected native Class findClass(String name)
throws java.lang.ClassNotFoundException;
// This can be package-private because we only call it from native
// code during startup.
static void initialize ()
{
instance.init();
system_instance.init();
}
// Define a package for something loaded natively.
void definePackageForNative(String className)
{
int lastDot = className.lastIndexOf('.');
if (lastDot != -1)
{
String packageName = className.substring(0, lastDot);
if (getPackage(packageName) == null)
{
// FIXME: this assumes we're defining the core, which
// isn't necessarily so. We could detect this and set up
// appropriately. We could also look at a manifest file
// compiled into the .so.
definePackage(packageName, "Java Platform API Specification",
"GNU", "1.4", "gcj", "GNU",
null, // FIXME: gcj version.
null);
}
}
}
// This keeps track of shared libraries we've already tried to load.
private HashSet tried_libraries = new HashSet();
// Holds one of the LIB_* constants; used to determine how shared
// library loads are done.
private int lib_control;
// The only VMClassLoader that can exist.
static VMClassLoader instance = new VMClassLoader();
// The system class loader.
static SystemClassLoader system_instance = new SystemClassLoader(instance);
private static final int LIB_FULL = 0;
private static final int LIB_CACHE = 1;
private static final int LIB_NEVER = 2;
}
@@ -1,79 +0,0 @@
// Native code for VMClassLoader
/* Copyright (C) 2002, 2003, 2005 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. */
#include <config.h>
#include <gcj/cni.h>
#include <jvm.h>
#include <gnu/gcj/runtime/VMClassLoader.h>
#include <java/lang/Class.h>
#include <java/lang/StringBuffer.h>
#include <java/net/URLClassLoader.h>
#include <java/lang/Runtime.h>
#include <java/util/HashSet.h>
jclass
gnu::gcj::runtime::VMClassLoader::findClass (jstring name)
{
_Jv_Utf8Const *name_u = _Jv_makeUtf8Const (name);
jclass klass = _Jv_FindClassInCache (name_u);
if (! klass && lib_control != LIB_NEVER)
{
// Turn `gnu.pkg.quux' into `lib-gnu-pkg-quux'. Then search for
// a module named (eg, on Linux) `lib-gnu-pkg-quux.so', followed
// by `lib-gnu-pkg.so' and `lib-gnu.so'. If loading one of
// these causes the class to appear in the cache, then use it.
java::lang::StringBuffer *sb = new java::lang::StringBuffer (JvNewStringLatin1("lib-"));
// Skip inner classes
jstring cn;
jint ci = name->indexOf('$');
if (ci == -1)
cn = name;
else
cn = name->substring (0, ci);
jstring so_base_name = (sb->append (cn)->toString ())->replace ('.', '-');
using namespace ::java::lang;
Runtime *rt = Runtime::getRuntime();
// Compare against `3' because that is the length of "lib".
while (! klass && so_base_name && so_base_name->length() > 3)
{
if (lib_control == LIB_CACHE)
{
// If we've already tried this name, we're done.
if (tried_libraries->contains(so_base_name))
break;
tried_libraries->add(so_base_name);
}
jboolean loaded = rt->loadLibraryInternal (so_base_name);
jint nd = so_base_name->lastIndexOf ('-');
if (nd == -1)
so_base_name = NULL;
else
so_base_name = so_base_name->substring (0, nd);
if (loaded)
klass = _Jv_FindClassInCache (name_u);
}
}
// Either define the package, or try loading using the interpreter.
if (klass)
definePackageForNative(name);
else
klass = java::net::URLClassLoader::findClass (name);
return klass;
}