Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  Main.java

  Sprache: JAVA
 

/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import static art.NonStandardExit.popFrame;
import static art.SuspendEvents.setupMethodExitTest;

import java.lang.reflect.Executable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Base64;
import java.util.EnumSet;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;

public class Main {
    private static void SafePrintStackTrace(StackTraceElement st[]) {
        for (StackTraceElement e : st) {
            System.out.println("\t" + e.getClassName() + "." + e.getMethodName() + "("
                               + (e.isNativeMethod() ? "Native Method" : e.getFileName()) + ")");
            if (e.getClassName().equals("art.Test1953") && e.getMethodName().equals("runTests")) {
                System.out.println("\t<Additional frames hidden>");
                break;
            }
        }
    }

    public void runTestOn(TestObject testObj, Method method) throws Exception {
        System.out.println("Single call with PopFrame on " + testObj);

        final Method methodExitCallback =
                TestObject.class.getDeclaredMethod("methodExitCallback", Object.class);
        final CountDownLatch continue_latch = new CountDownLatch(1);
        final CountDownLatch startup_latch = new CountDownLatch(1);
        Runnable await = () -> {
            try {
                startup_latch.countDown();
                continue_latch.await();
            } catch (Exception e) {
                throw new Error("Failed to await latch", e);
            }
        };
        Thread thr = new Thread(() -> {
            await.run();
            testObj.run();
            art.SuspendEvents.clearTestData(Thread.currentThread());
        });
        thr.start();

        // Wait until the other thread is started.
        startup_latch.await();

        // Setup suspension method on the thread.
        art.SuspendEvents.setupSuspendExceptionEvent(method, /*is_catch=*/ false, thr);
        art.SuspendEvents.enableMethodExitEvents(TestObject.class, methodExitCallback, thr);

        // Let the other thread go.
        continue_latch.countDown();

        // Wait for the other thread to hit the breakpoint/watchpoint/whatever and suspend itself
        // (without re-entering java)
        art.SuspendEvents.waitForSuspendHit(thr);

        art.SuspendEvents.disableExceptionEvents(thr);

        try {
            // Pop the frame.
            popFrame(thr);
        } catch (Exception e) {
            System.out.println("Failed to pop frame due to " + e);
            SafePrintStackTrace(e.getStackTrace());
        }


        // Start the other thread going again.
        art.Suspension.resume(thr);

        // Wait for the other thread to finish.
        thr.join();

        // See how many times calledFunction was called.
        System.out.println("result is " + testObj);
    }

    public static class TestObject implements Runnable {
        public static class TestError extends Error {}

        public int cnt;
        public int callerCnt;
        public boolean isJit;

        public TestObject(boolean isJit) {
            cnt = 0;
            callerCnt = 0;
            this.isJit = isJit;
        }

        public void run() {
            callerFunction();
        }

        public void callerFunction() {
            callerCnt++;
            try {
                if (isJit) {
                    // This function should be re-executed by the popFrame.
                    calledFunctionJit();
                } else {
                    // This function should be re-executed by the popFrame.
                    calledFunction();
                }
            } catch(TestError e) {
                System.out.println(e.getClass().getName() + " thrown and caught!");
            }
        }

        public void calledFunction() {
            cnt++;
            throw new TestError();
        }

        public void calledFunctionJit() {
            cnt++;
            throw new TestError();
        }

        public String toString() {
            return "TestObject { cnt: " + cnt + " callerCnt: " + callerCnt + " }";
        }

        public static void methodExitCallback(Object m) {
            System.out.println("MethodExitCallback " + m.toString());
        }
    }

    public void runTests() throws Exception {
        setupMethodExitTest();

        final Method calledFunction = TestObject.class.getDeclaredMethod("calledFunction");
        final Method calledFunctionJit = TestObject.class.getDeclaredMethod("calledFunctionJit");
        Main.ensureJitCompiled(TestObject.class"calledFunctionJit");

        runTestOn(new TestObject(false), calledFunction);
        runTestOn(new TestObject(true), calledFunctionJit);
    }

    public static void main(String[] args) throws Exception {
        System.loadLibrary(args[0]);
        new Main().runTests();
    }

    private static native void ensureJitCompiled(Class<?> c, String name);
}

Messung V0.5 in Prozent
C=84 H=92 G=87

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-29) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik