CriticalFailure() static private method

static private CriticalFailure ( string message, Exception x ) : void
message string
x Exception
return void
示例#1
0
        internal static void LoadRemappedTypes()
        {
            // if we're compiling the core, coreAssembly will be null
            Assembly coreAssembly = JVM.CoreAssembly;

            if (coreAssembly != null)
            {
                try
                {
                    Tracer.Info(Tracer.Runtime, "Core assembly: {0}", coreAssembly.Location);
                }
                catch (System.Security.SecurityException)
                {
                }
                RemappedClassAttribute[] remapped = AttributeHelper.GetRemappedClasses(coreAssembly);
                if (remapped.Length > 0)
                {
                    foreach (RemappedClassAttribute r in remapped)
                    {
                        Tracer.Info(Tracer.Runtime, "Remapping type {0} to {1}", r.RemappedType, r.Name);
                        remappedTypes.Add(r.RemappedType, r.Name);
                    }
                }
                else
                {
                    JVM.CriticalFailure("Failed to find core classes in core library", null);
                }
            }
        }
        internal virtual TypeWrapper GetWrapperFromAssemblyType(Type type)
        {
            //Tracer.Info(Tracer.Runtime, "GetWrapperFromAssemblyType: {0}", type.FullName);
            Debug.Assert(!type.Name.EndsWith("[]"), "!type.IsArray", type.FullName);
            Debug.Assert(AssemblyClassLoader.FromAssembly(type.Assembly) == this);

            TypeWrapper wrapper = GetLoader(type.Assembly).CreateWrapperForAssemblyType(type);

            if (wrapper != null)
            {
                if (type.IsGenericType && !type.IsGenericTypeDefinition)
                {
                    // in the case of "magic" implementation generic type instances we'll end up here as well,
                    // but then wrapper.GetClassLoader() will return this anyway
                    wrapper = wrapper.GetClassLoader().RegisterInitiatingLoader(wrapper);
                }
                else
                {
                    wrapper = RegisterInitiatingLoader(wrapper);
                }
                if (wrapper.TypeAsTBD != type && (!wrapper.IsRemapped || wrapper.TypeAsBaseType != type))
                {
                    // this really shouldn't happen, it means that we have two different types in our assembly that both
                    // have the same Java name
#if STATIC_COMPILER
                    throw new FatalCompilerErrorException(Message.AssemblyContainsDuplicateClassNames, type.FullName, wrapper.TypeAsTBD.FullName, wrapper.Name, type.Assembly.FullName);
#else
                    string msg = String.Format("\nType \"{0}\" and \"{1}\" both map to the same name \"{2}\".\n", type.FullName, wrapper.TypeAsTBD.FullName, wrapper.Name);
                    JVM.CriticalFailure(msg, null);
#endif
                }
                return(wrapper);
            }
            return(null);
        }
示例#3
0
        private static void EmitLoadCharArrayLiteral(CodeEmitter ilgen, string str, TypeWrapper tw)
        {
            ModuleBuilder mod = tw.GetClassLoader().GetTypeWrapperFactory().ModuleBuilder;
            // FXBUG on .NET 1.1 & 2.0 the value type that Ref.Emit automatically generates is public,
            // so we pre-create a non-public type with the right name here and it will "magically" use
            // that instead.
            // If we're running on Mono this isn't necessary, but for simplicitly we'll simply create
            // the type as well (it is useless, but all it does is waste a little space).
            int    length   = str.Length * 2;
            string typename = "$ArrayType$" + length;
            Type   type     = mod.GetType(typename, false, false);

            if (type == null)
            {
                if (tw.GetClassLoader().GetTypeWrapperFactory().ReserveName(typename))
                {
                    TypeBuilder tb = mod.DefineType(typename, TypeAttributes.Sealed | TypeAttributes.Class | TypeAttributes.ExplicitLayout | TypeAttributes.NotPublic, Types.ValueType, PackingSize.Size1, length);
                    AttributeHelper.HideFromJava(tb);
                    type = tb.CreateType();
                }
            }
            if (type == null ||
                !type.IsValueType ||
                type.StructLayoutAttribute.Pack != 1 || type.StructLayoutAttribute.Size != length)
            {
                // the type that we found doesn't match (must mean we've compiled a Java type with that name),
                // so we fall back to the string approach
                ilgen.Emit(OpCodes.Ldstr, str);
                ilgen.Emit(OpCodes.Call, Types.String.GetMethod("ToCharArray", Type.EmptyTypes));
                return;
            }
            ilgen.Emit(OpCodes.Ldc_I4, str.Length);
            ilgen.Emit(OpCodes.Newarr, Types.Char);
            ilgen.Emit(OpCodes.Dup);
            byte[] data = new byte[length];
            for (int j = 0; j < str.Length; j++)
            {
                data[j * 2 + 0] = (byte)(str[j] >> 0);
                data[j * 2 + 1] = (byte)(str[j] >> 8);
            }
            // NOTE we define a module field, because type fields on Mono don't use the global $ArrayType$<n> type.
            // NOTE this also means that this will only work during static compilation, because ModuleBuilder.CreateGlobalFunctions() must
            // be called before the field can be used.
            FieldBuilder fb = mod.DefineInitializedData("__<str>", data, FieldAttributes.Static | FieldAttributes.PrivateScope);

            // MONOBUG Type.Equals(Type) is broken on Mono. We have to use the virtual method that ends up in our implementation
            if (!fb.FieldType.Equals((object)type))
            {
                // this is actually relatively harmless, but I would like to know about it, so we abort and hope that users report this when they encounter it
                JVM.CriticalFailure("Unsupported runtime: ModuleBuilder.DefineInitializedData() field type mispredicted", null);
            }
            ilgen.Emit(OpCodes.Ldtoken, fb);
            ilgen.Emit(OpCodes.Call, JVM.Import(typeof(System.Runtime.CompilerServices.RuntimeHelpers)).GetMethod("InitializeArray", new Type[] { Types.Array, JVM.Import(typeof(RuntimeFieldHandle)) }));
        }
示例#4
0
 internal static TypeWrapper LoadClassCritical(string name)
 {
     try
     {
         return(GetBootstrapClassLoader().LoadClassByDottedName(name));
     }
     catch (Exception x)
     {
         JVM.CriticalFailure("Loading of critical class failed", x);
         return(null);
     }
 }
 internal AssemblyLoader(Assembly assembly)
 {
     this.assembly = assembly;
     modules       = assembly.GetModules(false);
     isJavaModule  = new bool[modules.Length];
     for (int i = 0; i < modules.Length; i++)
     {
         object[] attr;
         try
         {
             attr = AttributeHelper.GetJavaModuleAttributes(modules[i]);
         }
         catch (Exception x)
         {
             // HACK we handle exceptions here, because there is at least one obfuscator that produces
             // invalid assemblies that cause Module.GetCustomAttributes() to throw an exception
             JVM.CriticalFailure("Unexpected exception", x);
             throw null;
         }
         if (attr.Length > 0)
         {
             isJavaModule[i] = true;
             foreach (JavaModuleAttribute jma in attr)
             {
                 string[] map = jma.GetClassMap();
                 if (map != null)
                 {
                     if (nameMap == null)
                     {
                         nameMap = new Dictionary <string, string>();
                     }
                     for (int j = 0; j < map.Length; j += 2)
                     {
                         string key = map[j];
                         string val = map[j + 1];
                         // TODO if there is a name clash between modules, this will throw.
                         // Figure out how to handle that.
                         nameMap.Add(key, val);
                     }
                 }
             }
         }
         else
         {
             hasDotNetModule = true;
         }
     }
 }
示例#6
0
 private static bool CallerID_getCallerID(EmitIntrinsicContext eic)
 {
     if (eic.Caller.HasCallerID)
     {
         int arg = eic.Caller.GetParametersForDefineMethod().Length - 1;
         if (!eic.Caller.IsStatic)
         {
             arg++;
         }
         eic.Emitter.Emit(OpCodes.Ldarg, (short)arg);
         return(true);
     }
     else
     {
         JVM.CriticalFailure("CallerID.getCallerID() requires a HasCallerID annotation", null);
     }
     return(false);
 }
示例#7
0
 private static bool CallerID_getCallerID(DynamicTypeWrapper.FinishContext context, CodeEmitter ilgen, MethodWrapper method, MethodAnalyzer ma, int opcodeIndex, MethodWrapper caller, ClassFile classFile, Instruction[] code, InstructionFlags[] flags)
 {
     if (caller.HasCallerID)
     {
         int arg = caller.GetParametersForDefineMethod().Length - 1;
         if (!caller.IsStatic)
         {
             arg++;
         }
         ilgen.Emit(OpCodes.Ldarg, (short)arg);
         return(true);
     }
     else
     {
         JVM.CriticalFailure("CallerID.getCallerID() requires a HasCallerID annotation", null);
     }
     return(false);
 }
        internal static void LoadRemappedTypes()
        {
            // if we're compiling the core, coreAssembly will be null
            Assembly coreAssembly = JVM.CoreAssembly;

            if (coreAssembly != null && remappedTypes.Count == 0)
            {
                RemappedClassAttribute[] remapped = AttributeHelper.GetRemappedClasses(coreAssembly);
                if (remapped.Length > 0)
                {
                    foreach (RemappedClassAttribute r in remapped)
                    {
                        remappedTypes.Add(r.RemappedType, r.Name);
                    }
                }
                else
                {
                    JVM.CriticalFailure("Failed to find core classes in core library", null);
                }
            }
        }
示例#9
0
        private static bool CallerID_getCallerID(EmitIntrinsicContext eic)
        {
            if (eic.Caller.HasCallerID)
            {
                int arg = eic.Caller.GetParametersForDefineMethod().Length - 1;
                if (!eic.Caller.IsStatic)
                {
                    arg++;
                }
                eic.Emitter.Emit(OpCodes.Ldarg, (short)arg);
                return(true);
            }
            else
            {
#if STATIC_COMPILER
                throw new FatalCompilerErrorException(Message.CallerIDRequiresHasCallerIDAnnotation);
#else
                JVM.CriticalFailure("CallerID.getCallerID() requires a HasCallerID annotation", null);
                return(false);
#endif
            }
        }