| 1 |
/* |
| 2 |
* $Id$ |
| 3 |
* |
| 4 |
* Copyright (C) 2003-2009 JNode.org |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or modify it |
| 7 |
* under the terms of the GNU Lesser General Public License as published |
| 8 |
* by the Free Software Foundation; either version 2.1 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, but |
| 12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 14 |
* License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public License |
| 17 |
* along with this library; If not, write to the Free Software Foundation, Inc., |
| 18 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
package org.jnode.vm; |
| 22 |
|
| 23 |
import java.io.Writer; |
| 24 |
import java.util.HashMap; |
| 25 |
|
| 26 |
import org.jnode.annotation.PrivilegedActionPragma; |
| 27 |
import org.jnode.vm.classmgr.IMTBuilder; |
| 28 |
import org.jnode.vm.classmgr.SelectorMap; |
| 29 |
import org.jnode.vm.classmgr.VmIsolatedStatics; |
| 30 |
import org.jnode.vm.classmgr.VmMethod; |
| 31 |
import org.jnode.vm.classmgr.VmSharedStatics; |
| 32 |
import org.jnode.vm.classmgr.VmType; |
| 33 |
import org.jnode.vm.compiler.CompiledIMT; |
| 34 |
import org.jnode.vm.scheduler.VmProcessor; |
| 35 |
|
| 36 |
/** |
| 37 |
* @author Ewout Prangsma (epr@users.sourceforge.net) |
| 38 |
*/ |
| 39 |
public final class VmJavaClassLoader extends VmAbstractClassLoader { |
| 40 |
|
| 41 |
/** |
| 42 |
* The java classloader |
| 43 |
*/ |
| 44 |
private final ClassLoader loader; |
| 45 |
|
| 46 |
/** |
| 47 |
* The system classloader |
| 48 |
*/ |
| 49 |
private final VmSystemClassLoader systemLoader; |
| 50 |
|
| 51 |
/** |
| 52 |
* A className to VmType map for all loaded classes |
| 53 |
*/ |
| 54 |
private final HashMap<String, VmType> loadedClasses = new HashMap<String, VmType>(); |
| 55 |
|
| 56 |
/** |
| 57 |
* Initialize this class. |
| 58 |
* |
| 59 |
* @param loader |
| 60 |
*/ |
| 61 |
public VmJavaClassLoader(ClassLoader loader) { |
| 62 |
this.loader = loader; |
| 63 |
this.systemLoader = VmSystem.getSystemClassLoader(); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* @see org.jnode.vm.classmgr.VmClassLoader#asClassLoader() |
| 68 |
*/ |
| 69 |
public final ClassLoader asClassLoader() { |
| 70 |
return loader; |
| 71 |
} |
| 72 |
|
| 73 |
public void disassemble(VmMethod vmMethod, int optLevel, boolean enableTestCompilers, Writer writer) { |
| 74 |
systemLoader.disassemble(vmMethod, optLevel, enableTestCompilers, writer); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Compile the given IMT. |
| 79 |
*/ |
| 80 |
public CompiledIMT compileIMT(IMTBuilder builder) { |
| 81 |
return systemLoader.compileIMT(builder); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* @see org.jnode.vm.classmgr.VmClassLoader#findLoadedClass(java.lang.String) |
| 86 |
*/ |
| 87 |
public final VmType findLoadedClass(String className) { |
| 88 |
return (VmType) loadedClasses.get(className); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Add a class that has been loaded. |
| 93 |
* |
| 94 |
* @param name |
| 95 |
* @param cls |
| 96 |
*/ |
| 97 |
public final void addLoadedClass(String name, VmType cls) { |
| 98 |
loadedClasses.put(name, cls); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* @see org.jnode.vm.classmgr.VmClassLoader#getArchitecture() |
| 103 |
*/ |
| 104 |
public final VmArchitecture getArchitecture() { |
| 105 |
return systemLoader.getArchitecture(); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* @see org.jnode.vm.classmgr.VmClassLoader#isCompileRequired() |
| 110 |
*/ |
| 111 |
public final boolean isCompileRequired() { |
| 112 |
return systemLoader.isCompileRequired(); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* @see org.jnode.vm.classmgr.VmClassLoader#loadClass(java.lang.String, |
| 117 |
* boolean) |
| 118 |
*/ |
| 119 |
@PrivilegedActionPragma |
| 120 |
public final VmType<?> loadClass(String className, boolean resolve) |
| 121 |
throws ClassNotFoundException { |
| 122 |
final VmType<?> cls; |
| 123 |
if (className.charAt(0) == '[') { |
| 124 |
cls = loadArrayClass(className, resolve); |
| 125 |
addLoadedClass(className, cls); |
| 126 |
} else { |
| 127 |
final Class<?> javaType = loader.loadClass(className); |
| 128 |
cls = VmType.fromClass((Class<?>) javaType); |
| 129 |
} |
| 130 |
if (resolve) { |
| 131 |
cls.link(); |
| 132 |
} |
| 133 |
return cls; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* @see org.jnode.vm.classmgr.VmClassLoader#isSystemClassLoader() |
| 138 |
*/ |
| 139 |
public final boolean isSystemClassLoader() { |
| 140 |
return false; |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* @see org.jnode.vm.VmAbstractClassLoader#getSelectorMap() |
| 145 |
*/ |
| 146 |
protected final SelectorMap getSelectorMap() { |
| 147 |
return systemLoader.getSelectorMap(); |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* @see org.jnode.vm.VmAbstractClassLoader#getSharedStatics() |
| 152 |
*/ |
| 153 |
public final VmSharedStatics getSharedStatics() { |
| 154 |
return systemLoader.getSharedStatics(); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Gets the isolated statics table (of the current isolate) |
| 159 |
* |
| 160 |
* @return The statics table |
| 161 |
*/ |
| 162 |
public final VmIsolatedStatics getIsolatedStatics() { |
| 163 |
return VmProcessor.current().getIsolatedStatics(); |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* @see org.jnode.vm.classmgr.VmClassLoader#resourceExists(java.lang.String) |
| 168 |
*/ |
| 169 |
public final boolean resourceExists(String resName) { |
| 170 |
return false; |
| 171 |
} |
| 172 |
|
| 173 |
} |