changeset 121:bd7b676675af

Added two new examples for examining Java bytecode.
author ptisnovs
date Sat, 21 Jun 2014 19:48:01 +0200
parents 3942d1d67d2a
children 3b377525c48f
files ChangeLog bytecode/Java/Test21.java bytecode/Java/Test22.java
diffstat 3 files changed, 417 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Jun 15 19:42:20 2014 +0200
+++ b/ChangeLog	Sat Jun 21 19:48:01 2014 +0200
@@ -1,3 +1,9 @@
+2014-06-21  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* bytecode/Java/Test21.java:
+	* bytecode/Java/Test22.java:
+	Added two new examples for examining Java bytecode.
+
 2014-06-15  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* bytecode/Lua/Test17.lua:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bytecode/Java/Test21.java	Sat Jun 21 19:48:01 2014 +0200
@@ -0,0 +1,187 @@
+/**
+ * Pristup k prvkum jednorozmerneho pole.
+ */
+public class Test21 {
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu byte[]                                                 */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z pole.
+     */
+    static byte readItem(byte[] array, int index) {
+        return array[index];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(byte[] array, int index, byte value) {
+        array[index] = value;
+    }
+
+    /**
+     * Zvyseni hodnoty vsech prvku pole o jednicku.
+     */
+    static void modify(byte[] array) {
+        for (int i=0; i < array.length; i++) {
+            array[i]++;
+        }
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu short[]                                                */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z pole.
+     */
+    static short readItem(short[] array, short index) {
+        return array[index];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(short[] array, short index, short value) {
+        array[index] = value;
+    }
+
+    /**
+     * Zvyseni hodnoty vsech prvku pole o jednicku.
+     */
+    static void modify(short[] array) {
+        for (int i=0; i < array.length; i++) {
+            array[i]++;
+        }
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu int[]                                                  */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z pole.
+     */
+    static int readItem(int[] array, int index) {
+        return array[index];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(int[] array, int index, int value) {
+        array[index] = value;
+    }
+
+    /**
+     * Zvyseni hodnoty vsech prvku pole o jednicku.
+     */
+    static void modify(int[] array) {
+        for (int i=0; i < array.length; i++) {
+            array[i]++;
+        }
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu long[]                                                 */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z pole.
+     */
+    static long readItem(long[] array, int index) {
+        return array[index];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(long[] array, int index, long value) {
+        array[index] = value;
+    }
+
+    /**
+     * Zvyseni hodnoty vsech prvku pole o jednicku.
+     */
+    static void modify(long[] array) {
+        for (int i=0; i < array.length; i++) {
+            array[i]++;
+        }
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu float[]                                                */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z pole.
+     */
+    static float readItem(float[] array, int index) {
+        return array[index];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(float[] array, int index, float value) {
+        array[index] = value;
+    }
+
+    /**
+     * Zvyseni hodnoty vsech prvku pole o jednicku.
+     */
+    static void modify(float[] array) {
+        for (int i=0; i < array.length; i++) {
+            array[i]++;
+        }
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu double[]                                               */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z pole.
+     */
+    static double readItem(double[] array, int index) {
+        return array[index];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(double[] array, int index, double value) {
+        array[index] = value;
+    }
+
+    /**
+     * Zvyseni hodnoty vsech prvku pole o jednicku.
+     */
+    static void modify(double[] array) {
+        for (int i=0; i < array.length; i++) {
+            array[i]++;
+        }
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu Object[]                                               */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z pole.
+     */
+    static Object readItem(Object[] array, int index) {
+        return array[index];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(Object[] array, int index, Object value) {
+        array[index] = value;
+    }
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bytecode/Java/Test22.java	Sat Jun 21 19:48:01 2014 +0200
@@ -0,0 +1,224 @@
+/**
+ * Pristup k prvkum dvourozmerneho pole.
+ */
+public class Test22 {
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu byte[]                                                 */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z dvourozmerneho pole.
+     */
+    static byte readItem(byte[][] array, int index1, int index2) {
+        return array[index1][index2];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(byte[][] array, int index1, int index2, byte value) {
+        array[index1][index2] = value;
+    }
+
+    /**
+     * Vypocet sumy vsech prvku
+     */
+    static byte sum(byte[][] array) {
+        byte sum = 0;
+        for (int j = 0; j < array.length; j++) {
+            for (int i = 0; i < array[j].length; i++) {
+                sum += array[j][i];
+            }
+        }
+        return sum;
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu short[]                                                */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z dvourozmerneho pole.
+     */
+    static short readItem(short[][] array, int index1, int index2) {
+        return array[index1][index2];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(short[][] array, int index1, int index2, short value) {
+        array[index1][index2] = value;
+    }
+
+    /**
+     * Vypocet sumy vsech prvku
+     */
+    static short sum(short[][] array) {
+        short sum = 0;
+        for (int j = 0; j < array.length; j++) {
+            for (int i = 0; i < array[j].length; i++) {
+                sum += array[j][i];
+            }
+        }
+        return sum;
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu int[]                                                  */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z dvourozmerneho pole.
+     */
+    static int readItem(int[][] array, int index1, int index2) {
+        return array[index1][index2];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(int[][] array, int index1, int index2, int value) {
+        array[index1][index2] = value;
+    }
+
+    /**
+     * Vypocet sumy vsech prvku
+     */
+    static int sum(int[][] array) {
+        int sum = 0;
+        for (int j = 0; j < array.length; j++) {
+            for (int i = 0; i < array[j].length; i++) {
+                sum += array[j][i];
+            }
+        }
+        return sum;
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu long[]                                                 */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z dvourozmerneho pole.
+     */
+    static long readItem(long[][] array, int index1, int index2) {
+        return array[index1][index2];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(long[][] array, int index1, int index2, long value) {
+        array[index1][index2] = value;
+    }
+
+    /**
+     * Vypocet sumy vsech prvku
+     */
+    static long sum(long[][] array) {
+        long sum = 0;
+        for (int j = 0; j < array.length; j++) {
+            for (int i = 0; i < array[j].length; i++) {
+                sum += array[j][i];
+            }
+        }
+        return sum;
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu float[]                                                */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z dvourozmerneho pole.
+     */
+    static float readItem(float[][] array, int index1, int index2) {
+        return array[index1][index2];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(float[][] array, int index1, int index2, float value) {
+        array[index1][index2] = value;
+    }
+
+    /**
+     * Vypocet sumy vsech prvku
+     */
+    static float sum(float[][] array) {
+        float sum = 0;
+        for (int j = 0; j < array.length; j++) {
+            for (int i = 0; i < array[j].length; i++) {
+                sum += array[j][i];
+            }
+        }
+        return sum;
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu double[]                                               */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z dvourozmerneho pole.
+     */
+    static double readItem(double[][] array, int index1, int index2) {
+        return array[index1][index2];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(double[][] array, int index1, int index2, double value) {
+        array[index1][index2] = value;
+    }
+
+    /**
+     * Vypocet sumy vsech prvku
+     */
+    static double sum(double[][] array) {
+        double sum = 0;
+        for (int j = 0; j < array.length; j++) {
+            for (int i = 0; i < array[j].length; i++) {
+                sum += array[j][i];
+            }
+        }
+        return sum;
+    }
+
+    /* ---------------------------------------------------------------- */
+    /* Pole typu Object[]                                               */
+    /* ---------------------------------------------------------------- */
+
+    /**
+     * Nejjednodussi operace - precteni hodnoty prvku z dvourozmerneho pole.
+     */
+    static Object readItem(Object[][] array, int index1, int index2) {
+        return array[index1][index2];
+    }
+
+    /**
+     * Dalsi jednoducha operace - zapis hodnoty prvku do pole.
+     */
+    static void writeItem(Object[][] array, int index1, int index2, Object value) {
+        array[index1][index2] = value;
+    }
+
+    /**
+     * Vypocet sumy hash kodu vsech prvku pole.
+     */
+    static int sum(Object[][] array) {
+        int sum = 0;
+        for (int j = 0; j < array.length; j++) {
+            for (int i = 0; i < array[j].length; i++) {
+                sum += array[j][i].hashCode();
+            }
+        }
+        return sum;
+    }
+
+}
+