Eine aufbereitete Darstellung der Quelle

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

Benutzer

Quelle  Main.java

  Sprache: JAVA
 

/*
 * Copyright (C) 2016 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 java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

public class Main {
  public static native void assertIsInterpreted();
  public static native void ensureJitCompiled(Class<?> cls, String methodName);

  public static void assertEqual(String expected, String actual) {
    if (!expected.equals(actual)) {
      throw new Error("Assertion failed: " + expected + " != " + actual);
    }
  }

  public static void assertEqual(byte[] expected, String actual) throws Exception {
    String str = new String(expected, "UTF8");
    if (!str.equals(actual)) {
      throw new Error("Assertion failed: " + str + " != " + actual);
    }
  }

  // Create an empty int[] to force loading the int[] class before compiling
  // TestCase.deoptimizeNewInstance.
  // This makes sure the compiler can properly type int[] and not bail.
  static int[] emptyArray = new int[0];

  public static void main(String[] args) throws Throwable {
    System.loadLibrary(args[0]);
    Class<?> c = Class.forName("TestCase");
    String testString = "Hello world";
    byte[] testData = testString.getBytes("UTF8");

    {
      Method m = c.getMethod("vregAliasing"byte[].class);
      String result = (String) m.invoke(nullnew Object[] { testData });
      assertEqual(testString, result);
    }

    {
      c.getMethod("compareNewInstance").invoke(null, (Object[]) null);
    }

    {
      // If the JIT is enabled, ensure it has compiled the method to force the deopt.
      ensureJitCompiled(c, "deoptimizeNewInstance");
      Method m = c.getMethod("deoptimizeNewInstance"int[].classbyte[].class);
      try {
        m.invoke(nullnew Object[] { new int[] { 123 }, testData });
      } catch (InvocationTargetException ex) {
        if (ex.getCause() instanceof ArrayIndexOutOfBoundsException) {
          // Expected.
        } else {
          throw ex.getCause();
        }
      }
    }

    {
      Method m = c.getMethod("removeNewInstance"byte[].class);
      String result = (String) m.invoke(nullnew Object[] { testData });
      assertEqual(testString, result);
    }

    {
      Method m = c.getMethod("irreducibleLoopAndStringInit1"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, true });
      assertEqual(testString, result);
      result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      Method m = c.getMethod("irreducibleLoopAndStringInit2"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, true });
      assertEqual(testString, result);
      result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      Method m = c.getMethod("irreducibleLoopAndStringInit3"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, true });
      assertEqual(testString, result);
      result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      Method m = c.getMethod("loopAndStringInit"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, true });
      assertEqual(testString, result);
      result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      Method m = c.getMethod("loopAndStringInitAlias"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, true });
      assertEqual(testString, result);
      result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      Method m = c.getMethod("loopAndStringInitAndTest"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, true });
      assertEqual(testString, result);
      result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      // If the JIT is enabled, ensure it has compiled the method to force the deopt.
      ensureJitCompiled(c, "deoptimizeNewInstanceAfterLoop");
      Method m = c.getMethod(
          "deoptimizeNewInstanceAfterLoop"int[].classbyte[].classint.class);
      try {
        m.invoke(nullnew Object[] { new int[] { 123 }, testData, 0 });
      } catch (InvocationTargetException ex) {
        if (ex.getCause() instanceof ArrayIndexOutOfBoundsException) {
          // Expected.
        } else {
          throw ex.getCause();
        }
      }
    }
    {
      Method m = c.getMethod("loopAndStringInitAndPhi"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, true });
      assertEqual(testString, result);
      result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      Method m =
          c.getMethod("loopAndTwoStringInitAndPhi"byte[].classboolean.classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, falsefalse });
      assertEqual(testString, result);
      result = (String) m.invoke(nullnew Object[] { testData, falsetrue });
      assertEqual(testString, result);
    }
    {
      Method m = c.getMethod("stringAndCatch"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      Method m = c.getMethod("stringAndCatch2"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
    {
      Method m = c.getMethod("stringAndCatch3"byte[].classboolean.class);
      String result = (String) m.invoke(nullnew Object[] { testData, false });
      assertEqual(testString, result);
    }
  }

  public static Object $noinline$HiddenNull() {
    return null;
  }
}

Messung V0.5 in Prozent
C=81 H=81 G=80

¤ Dauer der Verarbeitung: 0.41 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