示例#1
0
        public static Delegate DynamicCreateDelegate(object obj, Type delegateType, string name, string sig)
        {
            TypeWrapper   tw = TypeWrapper.FromClass(ikvm.runtime.Util.getClassFromObject(obj));
            MethodWrapper mw = tw.GetMethodWrapper(name, sig, true);

            if (mw == null || mw.IsStatic || !mw.IsPublic)
            {
                MethodInfo      invoke         = delegateType.GetMethod("Invoke");
                ParameterInfo[] parameters     = invoke.GetParameters();
                Type[]          parameterTypes = new Type[parameters.Length + 1];
                parameterTypes[0] = typeof(object);
                for (int i = 0; i < parameters.Length; i++)
                {
                    parameterTypes[i + 1] = parameters[i].ParameterType;
                }
                System.Reflection.Emit.DynamicMethod dm = new System.Reflection.Emit.DynamicMethod("Invoke", invoke.ReturnType, parameterTypes);
                CodeEmitter ilgen = CodeEmitter.Create(dm);
                ilgen.Emit(System.Reflection.Emit.OpCodes.Ldstr, tw.Name + ".Invoke" + sig);
                ClassLoaderWrapper.GetBootstrapClassLoader()
                .LoadClassByDottedName(mw == null || mw.IsStatic ? "java.lang.AbstractMethodError" : "java.lang.IllegalAccessError")
                .GetMethodWrapper("<init>", "(Ljava.lang.String;)V", false)
                .EmitNewobj(ilgen);
                ilgen.Emit(System.Reflection.Emit.OpCodes.Throw);
                ilgen.DoEmit();
                return(dm.CreateDelegate(delegateType, obj));
            }
            else
            {
                mw.ResolveMethod();
                return(Delegate.CreateDelegate(delegateType, obj, (MethodInfo)mw.GetMethod()));
            }
        }
示例#2
0
    public static java.util.Enumeration getBootstrapResources(string name)
    {
#if FIRST_PASS
        return(null);
#else
        return(new ikvm.runtime.EnumerationWrapper(ClassLoaderWrapper.GetBootstrapClassLoader().GetResources(name)));
#endif
    }
示例#3
0
 public static java.net.URL getBootstrapResource(string name)
 {
     foreach (java.net.URL url in ClassLoaderWrapper.GetBootstrapClassLoader().GetResources(name))
     {
         return(url);
     }
     return(null);
 }
示例#4
0
        public static Delegate DynamicCreateDelegate(object obj, Type delegateType, string name, string sig)
        {
#if !WINRT
#if FIRST_PASS
            return(null);
#else
            TypeWrapper   tw = TypeWrapper.FromClass(ikvm.runtime.Util.getClassFromObject(obj));
            MethodWrapper mw = tw.GetMethodWrapper(name, sig, true);
            if (mw == null || mw.IsStatic || !mw.IsPublic)
            {
#if NO_REF_EMIT
                java.lang.invoke.MethodType methodType = MethodHandleUtil.GetDelegateMethodType(delegateType);
                if (methodType.parameterCount() > MethodHandleUtil.MaxArity)
                {
                    throw new NotImplementedException();
                }
                java.lang.invoke.MethodHandle exception = java.lang.invoke.MethodHandles.publicLookup()
                                                          .findConstructor(mw == null || mw.IsStatic ? typeof(java.lang.AbstractMethodError) : typeof(java.lang.IllegalAccessError),
                                                                           java.lang.invoke.MethodType.methodType(typeof(void), typeof(string)))
                                                          .bindTo(tw.Name + ".Invoke" + sig);
                return(Delegate.CreateDelegate(delegateType,
                                               java.lang.invoke.MethodHandles.dropArguments(
                                                   java.lang.invoke.MethodHandles.foldArguments(java.lang.invoke.MethodHandles.throwException(methodType.returnType(), exception.type().returnType()), exception),
                                                   0, methodType.parameterArray()).vmtarget, "Invoke"));
#else
                MethodInfo      invoke         = delegateType.GetMethod("Invoke");
                ParameterInfo[] parameters     = invoke.GetParameters();
                Type[]          parameterTypes = new Type[parameters.Length + 1];
                parameterTypes[0] = typeof(object);
                for (int i = 0; i < parameters.Length; i++)
                {
                    parameterTypes[i + 1] = parameters[i].ParameterType;
                }
                System.Reflection.Emit.DynamicMethod dm = new System.Reflection.Emit.DynamicMethod("Invoke", invoke.ReturnType, parameterTypes);
                CodeEmitter ilgen = CodeEmitter.Create(dm);
                ilgen.Emit(System.Reflection.Emit.OpCodes.Ldstr, tw.Name + ".Invoke" + sig);
                ClassLoaderWrapper.GetBootstrapClassLoader()
                .LoadClassByDottedName(mw == null || mw.IsStatic ? "java.lang.AbstractMethodError" : "java.lang.IllegalAccessError")
                .GetMethodWrapper("<init>", "(Ljava.lang.String;)V", false)
                .EmitNewobj(ilgen);
                ilgen.Emit(System.Reflection.Emit.OpCodes.Throw);
                ilgen.DoEmit();
                return(dm.CreateDelegate(delegateType, obj));
#endif
            }
            else
            {
                mw.ResolveMethod();
                return(Delegate.CreateDelegate(delegateType, obj, (MethodInfo)mw.GetMethod()));
            }
#endif
#else
            throw new NotImplementedException();
#endif
        }
示例#5
0
    // called from map.xml as a replacement for Class.getClassLoader() in sun.invoke.util.VerifyAccess.isTypeVisible()
    public static java.lang.ClassLoader Class_getClassLoader(java.lang.Class clazz)
    {
        TypeWrapper tw = TypeWrapper.FromClass(clazz);

        if (ClassLoaderWrapper.GetBootstrapClassLoader().LoadClassByDottedNameFast(tw.Name) == tw)
        {
            // if a class is visible from the bootstrap class loader, we have to return null to allow the visibility check to succeed
            return(null);
        }
        return(tw.GetClassLoader().GetJavaClassLoader());
    }
示例#6
0
 private static void LazyInitSystemPackages()
 {
     if (systemPackages == null)
     {
         Dictionary <string, string> dict = new Dictionary <string, string>();
         string path = VirtualFileSystem.GetAssemblyResourcesPath(JVM.CoreAssembly) + "resources.jar";
         foreach (string pkg in ClassLoaderWrapper.GetBootstrapClassLoader().GetPackages())
         {
             dict[pkg.Replace('.', '/') + "/"] = path;
         }
         Interlocked.CompareExchange(ref systemPackages, dict, null);
     }
 }
示例#7
0
    public static java.lang.Class findBootstrapClass(java.lang.ClassLoader thisClassLoader, string name)
    {
#if FIRST_PASS
        return(null);
#else
        TypeWrapper tw;
        try
        {
            tw = ClassLoaderWrapper.GetBootstrapClassLoader().LoadClassByDottedNameFast(name);
        }
        catch (RetargetableJavaException x)
        {
            throw x.ToJava();
        }
        return(tw != null ? tw.ClassObject : null);
#endif
    }
示例#8
0
        internal static bool IsEnabled(TypeWrapper tw)
        {
            string className = tw.Name;

            // match class name
            for (OptionNode n = classes; n != null; n = n.next)
            {
                if (n.name == className)
                {
                    return(n.enabled);
                }
            }

            // match package name
            if (packages != null)
            {
                int len = className.Length;
                while (len > 0 && className[--len] != '.')
                {
                    ;
                }

                do
                {
                    for (OptionNode n = packages; n != null; n = n.next)
                    {
#if WINRT
                        if (String.Compare(n.name, 0, className, 0, len) == 0 && len == n.name.Length)
#else
                        if (String.Compare(n.name, 0, className, 0, len, false, CultureInfo.InvariantCulture) == 0 && len == n.name.Length)
#endif
                        {
                            return(n.enabled);
                        }
                    }
                    while (len > 0 && className[--len] != '.')
                    {
                        ;
                    }
                } while (len > 0);
            }

            return(tw.GetClassLoader() == ClassLoaderWrapper.GetBootstrapClassLoader() ? sysAsserts : userAsserts);
        }
示例#9
0
 public static global::java.lang.Class LoadClass(object classLoader, Assembly assembly, string name)
 {
     try
     {
         TypeWrapper tw = null;
         if (classLoader == null)
         {
             tw = ClassLoaderWrapper.GetBootstrapClassLoader().LoadClassByDottedName(name);
         }
         else if (assembly != null)
         {
             AssemblyClassLoader_ acl = global::IKVM.Internal.AssemblyClassLoader.FromAssembly(assembly);
             tw = acl.GetLoadedClass(name);
             if (tw == null)
             {
                 tw = acl.LoadGenericClass(name);
             }
             if (tw == null)
             {
                 tw = acl.LoadReferenced(name);
             }
             if (tw == null)
             {
                 throw new ClassNotFoundException(name);
             }
         }
         else
         {
             // this must be a GenericClassLoader
             tw = ((GenericClassLoader)ClassLoaderWrapper.GetClassLoaderWrapper(classLoader)).LoadClassByDottedName(name);
         }
         Tracer.Info(Tracer.ClassLoading, "Loaded class \"{0}\" from {1}", name, classLoader == null ? "boot class loader" : classLoader);
         return(tw.ClassObject);
     }
     catch (RetargetableJavaException x)
     {
         Tracer.Info(Tracer.ClassLoading, "Failed to load class \"{0}\" from {1}", name, classLoader == null ? "boot class loader" : classLoader);
         throw x.ToJava();
     }
 }
示例#10
0
 public static void addBootClassPathAssembly(Assembly asm)
 {
     ClassLoaderWrapper.GetBootstrapClassLoader().AddDelegate(AssemblyClassLoader.FromAssembly(asm));
 }
示例#11
0
 internal override ClassLoaderWrapper GetClassLoader()
 {
     return(ClassLoaderWrapper.GetBootstrapClassLoader());
 }