Beispiel #1
0
        private void RunFinalizer(JavaLangAccess jla)
        {
            lock (this)
            {
                if (HasBeenFinalized())
                {
                    return;
                }
                Remove();
            }
            try
            {
                Object finalizee = this.Get();
                if (finalizee != null && !(finalizee is java.lang.Enum))
                {
                    jla.invokeFinalize(finalizee);

                    /* Clear stack slot containing this variable, to decrease
                     * the chances of false retention with a conservative GC */
                    finalizee = null;
                }
            }
            catch (Throwable)
            {
            }
            base.Clear();
        }
Beispiel #2
0
            public virtual void Run()
            {
                if (running)
                {
                    return;
                }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final sun.misc.JavaLangAccess jla = sun.misc.SharedSecrets.getJavaLangAccess();
                JavaLangAccess jla = SharedSecrets.JavaLangAccess;

                running = true;
                for (;;)
                {
                    Finalizer f;
                    lock (@lock)
                    {
                        f = Unfinalized;
                        if (f == null)
                        {
                            break;
                        }
                        Unfinalized = f.Next;
                    }
                    f.RunFinalizer(jla);
                }
            }
Beispiel #3
0
        // Private method to infer the caller's class and method names
        private void InferCaller()
        {
            NeedToInferCaller = false;
            JavaLangAccess access    = SharedSecrets.JavaLangAccess;
            Throwable      throwable = new Throwable();
            int            depth     = access.getStackTraceDepth(throwable);

            bool lookingForLogger = true;

            for (int ix = 0; ix < depth; ix++)
            {
                // Calling getStackTraceElement directly prevents the VM
                // from paying the cost of building the entire stack frame.
                StackTraceElement frame = access.getStackTraceElement(throwable, ix);
                String            cname = frame.ClassName;
                bool isLoggerImpl       = IsLoggerImplFrame(cname);
                if (lookingForLogger)
                {
                    // Skip all frames until we have found the first logger frame.
                    if (isLoggerImpl)
                    {
                        lookingForLogger = false;
                    }
                }
                else
                {
                    if (!isLoggerImpl)
                    {
                        // skip reflection call
                        if (!cname.StartsWith("java.lang.reflect.") && !cname.StartsWith("sun.reflect."))
                        {
                            // We've found the relevant frame.
                            SourceClassName  = cname;
                            SourceMethodName = frame.MethodName;
                            return;
                        }
                    }
                }
            }
            // We haven't found a suitable frame, so just punt.  This is
            // OK as we are only committed to making a "best effort" here.
        }
Beispiel #4
0
            public override void Run()
            {
                if (Running)
                {
                    return;
                }

                // Finalizer thread starts before System.initializeSystemClass
                // is called.  Wait until JavaLangAccess is available
                while (!VM.Booted)
                {
                    // delay until VM completes initialization
                    try
                    {
                        VM.awaitBooted();
                    }
                    catch (InterruptedException)
                    {
                        // ignore and continue
                    }
                }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final sun.misc.JavaLangAccess jla = sun.misc.SharedSecrets.getJavaLangAccess();
                JavaLangAccess jla = SharedSecrets.JavaLangAccess;

                Running = true;
                for (;;)
                {
                    try
                    {
                        Finalizer f = (Finalizer)Queue.Remove();
                        f.RunFinalizer(jla);
                    }
                    catch (InterruptedException)
                    {
                        // ignore and continue
                    }
                }
            }