Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,329 @@
/*
Copyright (C) 2002, 2003, 2004, 2005, 2006 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package gnu.java.net.protocol.ikvmres;
import cli.System.Reflection.Assembly;
import java.net.*;
import java.io.*;
class IkvmresURLConnection extends URLConnection
{
private InputStream inputStream;
IkvmresURLConnection(URL url)
{
super(url);
doOutput = false;
}
public void connect() throws IOException
{
if(!connected)
{
String assembly = url.getHost();
String resource = url.getFile();
if(assembly == null || resource == null || !resource.startsWith("/"))
{
throw new MalformedURLException(url.toString());
}
try
{
inputStream = Handler.readResourceFromAssembly(assembly, url.getPort(), resource);
connected = true;
}
catch(cli.System.IO.FileNotFoundException x)
{
throw (IOException)new FileNotFoundException(assembly).initCause(x);
}
catch(cli.System.BadImageFormatException x1)
{
throw (IOException)new IOException().initCause(x1);
}
catch(cli.System.Security.SecurityException x2)
{
throw (IOException)new IOException().initCause(x2);
}
}
}
public InputStream getInputStream() throws IOException
{
if(!connected)
{
connect();
}
return inputStream;
}
public OutputStream getOutputStream() throws IOException
{
throw new IOException("resource URLs are read only");
}
public long getLastModified()
{
return -1;
}
public int getContentLength()
{
return -1;
}
}
public class Handler extends URLStreamHandler
{
private static final String RFC2396_DIGIT = "0123456789";
private static final String RFC2396_LOWALPHA = "abcdefghijklmnopqrstuvwxyz";
private static final String RFC2396_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String RFC2396_ALPHA = RFC2396_LOWALPHA + RFC2396_UPALPHA;
private static final String RFC2396_ALPHANUM = RFC2396_DIGIT + RFC2396_ALPHA;
private static final String RFC2396_MARK = "-_.!~*'()";
private static final String RFC2396_UNRESERVED = RFC2396_ALPHANUM + RFC2396_MARK;
private static final String RFC2396_REG_NAME = RFC2396_UNRESERVED + "$,;:@&=+";
private static final String RFC2396_PCHAR = RFC2396_UNRESERVED + ":@&=+$,";
private static final String RFC2396_SEGMENT = RFC2396_PCHAR + ";";
private static final String RFC2396_PATH_SEGMENTS = RFC2396_SEGMENT + "/";
static InputStream readResourceFromAssembly(String assembly, int port, String resource)
throws cli.System.IO.FileNotFoundException,
cli.System.BadImageFormatException,
cli.System.Security.SecurityException,
IOException
{
if(assembly.equals("gen") && port != -1 && resource.endsWith(".class") && resource.indexOf('.') == resource.length() - 6)
{
ClassLoader loader = GetGenericClassLoaderById(port);
try
{
Class c = Class.forName(resource.substring(1, resource.length() - 6).replace('/', '.'), false, loader);
return new ByteArrayInputStream(GenerateStub(c));
}
catch(ClassNotFoundException _)
{
}
catch(LinkageError _)
{
}
}
return readResourceFromAssembly(LoadAssembly(assembly), resource);
}
public static InputStream readResourceFromAssembly(Assembly asm, String resource)
throws IOException
{
try
{
if(false) throw new cli.System.Security.SecurityException();
if(false) throw new cli.System.IO.FileNotFoundException();
if(false) throw new cli.System.IO.IOException();
return new ikvm.io.InputStreamWrapper(ReadResourceFromAssemblyImpl(asm, resource));
}
catch (cli.System.Security.SecurityException x)
{
throw (IOException)new IOException().initCause(x);
}
catch (cli.System.IO.FileNotFoundException x)
{
if(resource.endsWith(".class") && resource.indexOf('.') == resource.length() - 6)
{
Class c = LoadClassFromAssembly(asm, resource.substring(1, resource.length() - 6).replace('/', '.'));
if(c != null)
{
return new ByteArrayInputStream(GenerateStub(c));
}
}
throw (FileNotFoundException)new FileNotFoundException().initCause(x);
}
catch(cli.System.IO.IOException x)
{
throw (IOException)new IOException().initCause(x);
}
}
private static native byte[] GenerateStub(Class c);
private static native cli.System.IO.Stream ReadResourceFromAssemblyImpl(Assembly asm, String resource);
private static native Class LoadClassFromAssembly(Assembly asm, String className);
private static native Assembly LoadAssembly(String name)
throws cli.System.IO.FileNotFoundException, cli.System.BadImageFormatException, cli.System.Security.SecurityException;
private static native ClassLoader GetGenericClassLoaderById(int id);
protected URLConnection openConnection(URL url) throws IOException
{
return new IkvmresURLConnection(url);
}
protected void parseURL(URL url, String url_string, int start, int end)
{
try
{
// NOTE originally I wanted to use java.net.URI to handling parsing and constructing of these things,
// but it turns out that URI uses regex and that depends on resource loading...
url_string = url_string.substring(start, end);
if(url_string.startsWith("//"))
{
int slash = url_string.indexOf('/', 2);
if(slash == -1)
{
throw new RuntimeException("ikvmres: URLs must contain path");
}
String assembly = unquote(url_string.substring(2, slash));
String file = unquote(url_string.substring(slash));
setURL(url, "ikvmres", assembly, -1, file, null);
}
else if(url_string.startsWith("/"))
{
setURL(url, "ikvmres", url.getHost(), -1, url_string, null);
}
else
{
String[] baseparts = ((cli.System.String)(Object)url.getFile()).Split(new char[] { '/' });
String[] relparts = ((cli.System.String)(Object)url_string).Split(new char[] { '/' });
String[] target = new String[baseparts.length + relparts.length - 1];
for(int i = 1; i < baseparts.length; i++)
{
target[i - 1] = baseparts[i];
}
int p = baseparts.length - 2;
for(int i = 0; i < relparts.length; i++)
{
if(relparts[i].equals("."))
{
}
else if(relparts[i].equals(".."))
{
p = Math.max(0, p - 1);
}
else
{
target[p++] = relparts[i];
}
}
StringBuffer file = new StringBuffer();
for(int i = 0; i < p; i++)
{
file.append('/').append(target[i]);
}
setURL(url, "ikvmres", url.getHost(), -1, file.toString(), null);
}
}
catch(URISyntaxException x)
{
throw new RuntimeException(x.getMessage());
}
}
protected String toExternalForm(URL url)
{
// NOTE originally I wanted to use java.net.URI to handle parsing and constructing of these things,
// but it turns out that URI uses regex and that depends on resource loading...
return "ikvmres://" + quote(url.getHost(), RFC2396_REG_NAME) + quote(url.getFile(), RFC2396_PATH_SEGMENTS);
}
protected InetAddress getHostAddress(URL url)
{
return null;
}
private static String quote (String str, String legalCharacters)
{
StringBuffer sb = new StringBuffer(str.length());
for (int i = 0; i < str.length(); i++)
{
char c = str.charAt(i);
if (legalCharacters.indexOf(c) == -1)
{
String hex = "0123456789ABCDEF";
if (c <= 127)
{
sb.append('%')
.append(hex.charAt(c / 16))
.append(hex.charAt(c % 16));
}
else
{
try
{
// this is far from optimal, but it works
byte[] utf8 = str.substring(i, i + 1).getBytes("utf-8");
for (int j = 0; j < utf8.length; j++)
{
sb.append('%')
.append(hex.charAt((utf8[j] & 0xff) / 16))
.append(hex.charAt((utf8[j] & 0xff) % 16));
}
}
catch (java.io.UnsupportedEncodingException x)
{
throw (Error)new InternalError().initCause(x);
}
}
}
else
{
sb.append(c);
}
}
return sb.toString();
}
private static String unquote (String str)
throws URISyntaxException
{
if (str == null)
return null;
byte[] buf = new byte[str.length()];
int pos = 0;
for (int i = 0; i < str.length(); i++)
{
char c = str.charAt(i);
if (c > 127)
throw new URISyntaxException(str, "Invalid character");
if (c == '%')
{
if (i + 2 >= str.length())
throw new URISyntaxException(str, "Invalid quoted character");
String hex = "0123456789ABCDEF";
int hi = hex.indexOf(str.charAt(++i));
int lo = hex.indexOf(str.charAt(++i));
if (lo < 0 || hi < 0)
throw new URISyntaxException(str, "Invalid quoted character");
buf[pos++] = (byte)(hi * 16 + lo);
}
else
{
buf[pos++] = (byte)c;
}
}
try
{
return new String(buf, 0, pos, "utf-8");
}
catch (java.io.UnsupportedEncodingException x2)
{
throw (Error)new InternalError().initCause(x2);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
/*
Copyright (C) 2006-2013 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
// HACK because of historical reasons this class' source lives in ikvm/internal instead of ikvm/runtime
package ikvm.runtime;
import cli.System.Reflection.Assembly;
import gnu.java.util.EmptyEnumeration;
import ikvm.lang.Internal;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Vector;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
public final class AssemblyClassLoader extends ClassLoader
{
private boolean packagesDefined;
// This constructor is used to manually construct an AssemblyClassLoader that is used
// as a delegation parent for custom assembly class loaders.
//
// In that case the class loader object graph looks like this:
//
// +---------------------------------+
// |IKVM.Internal.AssemblyClassLoader|
// +---------------------------------+
// || /\ /\
// \/ || ||
// +-------------------+ ||
// |Custom Class Loader| +--------------------------------+
// +-------------------+ |ikvm.runtime.AssemblyClassLoader|
// +--------------------------------+
//
public AssemblyClassLoader(Assembly assembly)
{
super(null);
setWrapper(assembly);
}
private native void setWrapper(Assembly assembly);
// this constructor is used by the runtime and calls a privileged
// ClassLoader constructor to avoid the security check
AssemblyClassLoader()
{
super(null, null);
}
@Override
protected native Class loadClass(String name, boolean resolve) throws ClassNotFoundException;
@Override
public native URL getResource(String name);
@Override
public native Enumeration<URL> getResources(String name) throws IOException;
@Override
protected native URL findResource(String name);
@Override
protected native Enumeration<URL> findResources(String name) throws IOException;
private synchronized void lazyDefinePackagesCheck()
{
if(!packagesDefined)
{
packagesDefined = true;
lazyDefinePackages();
}
}
private native void lazyDefinePackages();
@Override
protected Package getPackage(String name)
{
lazyDefinePackagesCheck();
return super.getPackage(name);
}
@Override
protected Package[] getPackages()
{
lazyDefinePackagesCheck();
return super.getPackages();
}
@Override
public native String toString();
// return the ClassLoader for the assembly. Note that this doesn't have to be an AssemblyClassLoader.
public static native ClassLoader getAssemblyClassLoader(Assembly asm);
}
final class GenericClassLoader extends ClassLoader
{
// this constructor avoids the security check in ClassLoader by passing in null as the security manager
// to the IKVM specific constructor in ClassLoader
GenericClassLoader()
{
super(null, null);
}
@Override
public native String toString();
@Override
public URL getResource(String name)
{
Enumeration<URL> e = getResources(name);
return e.hasMoreElements()
? e.nextElement()
: null;
}
@Override
public native Enumeration<URL> getResources(String name);
@Override
protected native URL findResource(String name);
@Override
protected Enumeration<URL> findResources(String name)
{
Vector<URL> v = new Vector<URL>();
URL url = findResource(name);
if (url != null)
{
v.add(url);
}
return v.elements();
}
}

View File

@@ -0,0 +1,120 @@
/*
Copyright (C) 2008 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.internal;
import cli.System.Type;
import cli.System.Diagnostics.StackFrame;
import cli.System.Reflection.Assembly;
public abstract class CallerID
{
private Class clazz;
private ClassLoader classLoader;
protected CallerID() { }
@ikvm.lang.Internal
public final Class getCallerClass()
{
if (clazz == null)
{
clazz = GetClass();
}
return clazz;
}
@ikvm.lang.Internal
public final ClassLoader getCallerClassLoader()
{
ClassLoader cl = classLoader;
if (cl == null)
{
cl = classLoader = GetClassLoader();
if (cl == null)
{
cl = classLoader = ClassLoader.DUMMY;
}
}
return cl == ClassLoader.DUMMY ? null : cl;
}
@ikvm.lang.Internal
public static CallerID create(cli.System.Diagnostics.StackFrame frame)
{
return create(frame.GetMethod());
}
@ikvm.lang.Internal
public static CallerID create(final cli.System.Reflection.MethodBase method)
{
return new CallerID() {
Class GetClass() {
if (method == null) {
// this happens if a native thread attaches and calls back into Java
return null;
}
Type type = method.get_DeclaringType();
if (type == null) {
// TODO we probably should return a class corresponding to <Module>
throw new InternalError();
}
return ikvm.runtime.Util.getClassFromTypeHandle(type.get_TypeHandle());
}
ClassLoader GetClassLoader() {
if (method == null) {
// this happens if a native thread attaches and calls back into Java
return null;
}
Assembly asm = method.get_Module().get_Assembly();
return GetAssemblyClassLoader(asm);
}
};
}
// this is a shortcut for use inside the core class library, it removes the need to create a nested type for every caller
@ikvm.lang.Internal
public static CallerID create(final cli.System.RuntimeTypeHandle typeHandle)
{
return new CallerID() {
Class GetClass() {
return ikvm.runtime.Util.getClassFromTypeHandle(typeHandle);
}
ClassLoader GetClassLoader() {
// since this optimization is only available inside the core class library, we know that the class loader is null
return null;
}
};
}
@ikvm.lang.Internal
public static CallerID getCallerID()
{
// this is a compiler intrinsic, so there is no meaningful implementation here
return null;
}
native Class GetClass();
native ClassLoader GetClassLoader();
static native ClassLoader GetAssemblyClassLoader(Assembly asm);
}

View File

@@ -0,0 +1,65 @@
/*
Copyright (C) 2006 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.internal;
import cli.System.IFormatProvider;
import cli.System.IFormattable;
import ikvm.lang.CIL;
import ikvm.lang.Internal;
@Internal
public final class Formatter
{
private Formatter() {}
public static String ToString(Byte b, String format, IFormatProvider provider)
{
return CIL.box_sbyte(b.byteValue()).ToString(format, provider);
}
public static String ToString(Short s, String format, IFormatProvider provider)
{
return CIL.box_short(s.shortValue()).ToString(format, provider);
}
public static String ToString(Integer i, String format, IFormatProvider provider)
{
return CIL.box_int(i.intValue()).ToString(format, provider);
}
public static String ToString(Long l, String format, IFormatProvider provider)
{
return CIL.box_long(l.longValue()).ToString(format, provider);
}
public static String ToString(Float f, String format, IFormatProvider provider)
{
return CIL.box_float(f.floatValue()).ToString(format, provider);
}
public static String ToString(Double d, String format, IFormatProvider provider)
{
return CIL.box_double(d.doubleValue()).ToString(format, provider);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
package ikvm.internal;
public class Library
{
private static final LibraryVMInterface impl = new java.lang.LibraryVMInterfaceImpl();
public static LibraryVMInterface getImpl()
{
return impl;
}
}

View File

@@ -0,0 +1,62 @@
/*
Copyright (C) 2004, 2005, 2006, 2007 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.internal;
public interface LibraryVMInterface
{
Object newClass(Object wrapper, Object protectionDomain, Object classLoader);
Object getWrapperFromClass(Object clazz);
Object getWrapperFromField(Object field);
Object getWrapperFromMethodOrConstructor(Object methodOrConstructor);
Object getWrapperFromClassLoader(Object classLoader);
void setWrapperForClassLoader(Object classLoader, Object wrapper);
Object box(Object val);
Object unbox(Object val);
Throwable mapException(Throwable t);
void jniWaitUntilLastThread();
void jniDetach();
void setThreadGroup(Object group);
Object newConstructor(Object clazz, Object wrapper);
Object newMethod(Object clazz, Object wrapper);
Object newField(Object clazz, Object wrapper);
Object newDirectByteBuffer(cli.System.IntPtr address, int capacity);
cli.System.IntPtr getDirectBufferAddress(Object buffer);
int getDirectBufferCapacity(Object buffer);
void setProperties(cli.System.Collections.Hashtable props);
boolean runFinalizersOnExit();
Object newAnnotation(Object classLoader, Object definition);
Object newAnnotationElementValue(Object classLoader, Object expectedClass, Object definition);
Object newAssemblyClassLoader(cli.System.Reflection.Assembly assembly);
}

View File

@@ -0,0 +1,52 @@
/*
Copyright (C) 2008 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.internal;
import cli.System.Activator;
import cli.System.Reflection.BindingFlags;
import cli.System.Reflection.FieldInfo;
import cli.System.Reflection.MethodInfo;
import cli.System.Type;
final class MonoUtils
{
static String unameProperty(String field)
{
Type syscallType = Type.GetType("Mono.Unix.Native.Syscall, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
Type utsnameType = Type.GetType("Mono.Unix.Native.Utsname, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
if (syscallType != null && utsnameType != null)
{
Object[] arg = new Object[] { Activator.CreateInstance(utsnameType) };
MethodInfo uname = syscallType.GetMethod("uname", new Type[] { utsnameType.MakeByRefType() });
FieldInfo fi = utsnameType.GetField(field);
if (uname != null && fi != null)
{
uname.Invoke(null, arg);
return (String)fi.GetValue(arg[0]);
}
}
return null;
}
}

View File

@@ -0,0 +1,62 @@
package ikvm.internal;
import ikvm.lang.Internal;
@Internal
public final class Util
{
private Util() {}
public static final boolean MONO = cli.System.Type.GetType("Mono.Runtime") != null;
public static final boolean WINDOWS;
public static final boolean MACOSX;
static
{
switch (cli.System.Environment.get_OSVersion().get_Platform().Value)
{
case cli.System.PlatformID.Win32NT:
case cli.System.PlatformID.Win32Windows:
case cli.System.PlatformID.Win32S:
case cli.System.PlatformID.WinCE:
WINDOWS = true;
MACOSX = false;
break;
case cli.System.PlatformID.MacOSX:
WINDOWS = false;
MACOSX = true;
break;
case cli.System.PlatformID.Unix:
WINDOWS = false;
// as of version 2.6, Mono still returns Unix when running on MacOSX
MACOSX = "Darwin".equals(MonoUtils.unameProperty("sysname"));
break;
default:
WINDOWS = false;
MACOSX = false;
break;
}
}
public static boolean rangeCheck(int arrayLength, int offset, int length)
{
return offset >= 0
&& offset <= arrayLength
&& length >= 0
&& length <= arrayLength - offset;
}
public static String SafeGetEnvironmentVariable(String name)
{
try
{
if (false) throw new cli.System.Security.SecurityException();
return cli.System.Environment.GetEnvironmentVariable(name);
}
catch (cli.System.Security.SecurityException _)
{
return null;
}
}
}

View File

@@ -0,0 +1,155 @@
/*
Copyright (C) 2006, 2007 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.internal;
import cli.System.GC;
import cli.System.WeakReference;
@ikvm.lang.Internal
public final class WeakIdentityMap
{
private WeakReference[] keys = new WeakReference[16];
private Object[] values = new Object[keys.length];
public WeakIdentityMap()
{
for (int i = 0; i < keys.length; i++)
{
keys[i] = new WeakReference(null, true);
// NOTE we suppress finalization, to make sure the WeakReference continues to work
// while the AppDomain is finalizing for unload (note that for this to work,
// the code that instantiates us also has to call SuppressFinalize on us.)
GC.SuppressFinalize(keys[i]);
}
}
protected void finalize()
{
for (int i = 0; i < keys.length; i++)
{
if (keys[i] != null)
{
GC.ReRegisterForFinalize(keys[i]);
}
}
}
public synchronized Object remove(Object key)
{
for (int i = 0; i < keys.length; i++)
{
if (keys[i].get_Target() == key)
{
Object value = values[i];
keys[i].set_Target(null);
values[i] = null;
return value;
}
}
return null;
}
// Note that null values are supported, null keys are not
public synchronized void put(Object key, Object value)
{
if (key == null)
throw new NullPointerException();
putImpl(key, value, true);
}
private void putImpl(Object key, Object value, boolean tryGC)
{
int emptySlot = -1;
int keySlot = -1;
for (int i = 0; i < keys.length; i++)
{
Object k = keys[i].get_Target();
if (k == null)
{
emptySlot = i;
values[i] = null;
}
else if (k == key)
{
keySlot = i;
}
}
if (keySlot != -1)
{
values[keySlot] = value;
}
else if (emptySlot != -1)
{
keys[emptySlot].set_Target(key);
values[emptySlot] = value;
}
else
{
if (tryGC)
{
GC.Collect(0);
putImpl(key, value, false);
return;
}
int len = keys.length;
WeakReference[] newkeys = new WeakReference[len * 2];
Object[] newvalues = new Object[newkeys.length];
cli.System.Array.Copy((cli.System.Array)(Object)keys, (cli.System.Array)(Object)newkeys, len);
cli.System.Array.Copy((cli.System.Array)(Object)values, (cli.System.Array)(Object)newvalues, len);
keys = newkeys;
values = newvalues;
for (int i = len; i < keys.length; i++)
{
keys[i] = new WeakReference(null, true);
GC.SuppressFinalize(keys[i]);
}
keys[len].set_Target(key);
values[len] = value;
}
}
public synchronized Object get(Object key)
{
for (int i = 0; i < keys.length; i++)
{
if (keys[i].get_Target() == key)
{
return values[i];
}
}
return null;
}
public synchronized boolean containsKey(Object key)
{
for (int i = 0; i < keys.length; i++)
{
if (keys[i].get_Target() == key)
{
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,29 @@
/*
Copyright (C) 2007 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.internal;
import java.lang.annotation.*;
@Target({})
public @interface __unspecified {}

View File

@@ -0,0 +1,239 @@
/*
Copyright (C) 2006, 2007 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.io;
public final class InputStreamWrapper extends java.io.InputStream
{
private cli.System.IO.Stream stream;
private long markPosition = -1;
private boolean atEOF;
public InputStreamWrapper(cli.System.IO.Stream stream)
{
this.stream = stream;
}
public int read() throws java.io.IOException
{
try
{
if (false) throw new cli.System.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException(null);
int i = stream.ReadByte();
if (i == -1)
{
atEOF = true;
}
return i;
}
catch (cli.System.IO.IOException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
catch (cli.System.ObjectDisposedException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
}
public int read(byte[] b) throws java.io.IOException
{
return read(b, 0, b.length);
}
public int read(byte[] b, int off, int len) throws java.io.IOException
{
if (b == null)
{
throw new NullPointerException();
}
if (off < 0 || len < 0 || b.length - off < len)
{
throw new IndexOutOfBoundsException();
}
if (len == 0)
{
return 0;
}
try
{
if (false) throw new cli.System.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException(null);
int count = stream.Read(b, off, len);
if (count == 0)
{
atEOF = true;
return -1;
}
return count;
}
catch (cli.System.IO.IOException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
catch (cli.System.ObjectDisposedException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
}
public long skip(long n) throws java.io.IOException
{
if (n <= 0)
{
return 0;
}
else if (stream.get_CanSeek())
{
try
{
if (false) throw new cli.System.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException(null);
long pos = stream.get_Position();
n = Math.min(n, Math.max(0, stream.get_Length() - pos));
stream.set_Position(pos + n);
return n;
}
catch (cli.System.IO.IOException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
catch (cli.System.ObjectDisposedException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
}
else
{
return super.skip(n);
}
}
public int available() throws java.io.IOException
{
if (stream.get_CanSeek())
{
try
{
if (false) throw new cli.System.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException(null);
long val = stream.get_Length() - stream.get_Position();
return (int)Math.min(Math.max(val, 0), Integer.MAX_VALUE);
}
catch (cli.System.IO.IOException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
catch (cli.System.ObjectDisposedException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
}
else
{
// It turns out that it's important that available() return non-zero when
// data is still available, because BufferedInputStream uses the non-zero
// return value as a cue to continue reading.
// As suggested by Mark Reinhold, we emulate InflaterInputStream's behavior
// and return 0 after we've reached EOF and otherwise 1.
return atEOF ? 0 : 1;
}
}
public void close() throws java.io.IOException
{
stream.Close();
}
public void mark(int readlimit)
{
if (stream.get_CanSeek())
{
try
{
if (false) throw new cli.System.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException(null);
markPosition = stream.get_Position();
}
catch (cli.System.IO.IOException x)
{
}
catch (cli.System.ObjectDisposedException x)
{
}
}
}
public void reset() throws java.io.IOException
{
if (!stream.get_CanSeek())
{
throw new java.io.IOException("mark/reset not supported");
}
if (markPosition == -1)
{
throw new java.io.IOException("no mark available");
}
try
{
if (false) throw new cli.System.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException(null);
stream.set_Position(markPosition);
}
catch (cli.System.IO.IOException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
catch (cli.System.ObjectDisposedException x)
{
java.io.IOException ex = new java.io.IOException();
ex.initCause(x);
throw ex;
}
}
public boolean markSupported()
{
return stream.get_CanSeek();
}
}

View File

@@ -0,0 +1,55 @@
/*
Copyright (C) 2003, 2004, 2005 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.lang;
public class CIL
{
public static native byte unbox_byte(Object o);
public static native boolean unbox_boolean(Object o);
public static native short unbox_short(Object o);
public static native char unbox_char(Object o);
public static native int unbox_int(Object o);
public static native float unbox_float(Object o);
public static native long unbox_long(Object o);
public static native double unbox_double(Object o);
public static native cli.System.Byte box_byte(byte v);
public static native cli.System.Boolean box_boolean(boolean v);
public static native cli.System.Int16 box_short(short v);
public static native cli.System.Char box_char(char v);
public static native cli.System.Int32 box_int(int v);
public static native cli.System.Single box_float(float v);
public static native cli.System.Int64 box_long(long v);
public static native cli.System.Double box_double(double v);
public static native cli.System.SByte box_sbyte(byte v);
public static native cli.System.UInt16 box_ushort(short v);
public static native cli.System.UInt32 box_uint(int v);
public static native cli.System.UInt64 box_ulong(long v);
public static native byte unbox_sbyte(cli.System.SByte v);
public static native short unbox_ushort(cli.System.UInt16 v);
public static native int unbox_uint(cli.System.UInt32 v);
public static native long unbox_ulong(cli.System.UInt64 v);
}

View File

@@ -0,0 +1,40 @@
/*
Copyright (C) 2011 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.lang;
import java.lang.annotation.*;
/**
* Can be used to define an unmanaged export for a static method.
* Only works with ikvmc compiled code.
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.METHOD })
public @interface DllExport
{
String name();
int ordinal();
}

View File

@@ -0,0 +1,38 @@
/*
Copyright (C) 2006 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.lang;
import java.lang.annotation.*;
/**
* Can be used to mark public types or members as internal (i.e. private to the assembly)
*
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
public @interface Internal
{
}

View File

@@ -0,0 +1,69 @@
/*
Copyright (C) 2007 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.lang;
import cli.System.Collections.IEnumerator;
import cli.System.InvalidOperationException;
import ikvm.runtime.Util;
import java.util.Iterator;
public final class IterableEnumerator implements IEnumerator
{
private static final Object UNDEFINED = new Object();
private final Iterable src;
private Iterator iter;
private Object current;
public IterableEnumerator(Iterable src)
{
this.src = src;
Reset();
}
public boolean MoveNext()
{
if (iter.hasNext())
{
current = iter.next();
return true;
}
current = UNDEFINED;
return false;
}
public Object get_Current()
{
if (current == UNDEFINED)
{
Util.throwException(new InvalidOperationException());
}
return current;
}
public void Reset()
{
iter = src.iterator();
current = UNDEFINED;
}
}

View File

@@ -0,0 +1,70 @@
/*
Copyright (C) 2008 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.lang;
import cli.System.Collections.IDictionaryEnumerator;
import cli.System.Collections.DictionaryEntry;
import java.util.Map;
public final class MapEnumerator implements IDictionaryEnumerator
{
private final Map map;
private final IterableEnumerator keys;
public MapEnumerator(Map map)
{
this.map = map;
keys = new IterableEnumerator(map.keySet());
}
public Object get_Current()
{
return new DictionaryEntry(get_Key(), get_Value());
}
public boolean MoveNext()
{
return keys.MoveNext();
}
public void Reset()
{
keys.Reset();
}
public DictionaryEntry get_Entry()
{
return new DictionaryEntry(get_Key(), get_Value());
}
public Object get_Key()
{
return keys.get_Current();
}
public Object get_Value()
{
return map.get(keys.get_Current());
}
}

View File

@@ -0,0 +1,12 @@
package ikvm.lang;
import java.lang.annotation.*;
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.FIELD })
public @interface Property
{
String get();
String set() default "";
}

View File

@@ -0,0 +1,71 @@
/*
Copyright (C) 2007 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package ikvm.runtime;
import cli.System.AppDomain;
import cli.System.Reflection.Assembly;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Vector;
public final class AppDomainAssemblyClassLoader extends ClassLoader
{
public AppDomainAssemblyClassLoader(Assembly assembly)
{
super(new AssemblyClassLoader(assembly));
}
protected Class findClass(String name) throws ClassNotFoundException
{
Assembly[] assemblies = AppDomain.get_CurrentDomain().GetAssemblies();
for (int i = 0; i < assemblies.length; i++)
{
Class c = loadClassFromAssembly(assemblies[i], name);
if (c != null)
{
return c;
}
}
throw new ClassNotFoundException(name);
}
private static native Class loadClassFromAssembly(Assembly asm, String className);
protected native URL findResource(String name);
// we override getResources() instead of findResources() to be able to filter duplicates
public Enumeration<URL> getResources(String name) throws IOException
{
Vector<URL> v = new Vector<URL>();
for (Enumeration<URL> e = super.getResources(name); e.hasMoreElements(); )
{
v.add(e.nextElement());
}
getResources(v, name);
return v.elements();
}
private static native void getResources(Vector<URL> v, String name);
}

Some files were not shown because too many files have changed in this diff Show More