1 /*
   2  * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.jtt.micro;
  24 
  25 import org.junit.Test;
  26 
  27 import org.graalvm.compiler.jtt.JTTTest;
  28 
  29 public class FloatingReads extends JTTTest {
  30 
  31     public static long init = Runtime.getRuntime().totalMemory();
  32     private final int f = 10;
  33     private int a;
  34     private int b;
  35     private int c;
  36 
  37     public int test(int d) {
  38         a = 3;
  39         b = 5;
  40         c = 7;
  41         for (int i = 0; i < d; i++) {
  42             if (i % 2 == 0) {
  43                 a += b;
  44             }
  45             if (i % 4 == 0) {
  46                 b += c;
  47             } else if (i % 3 == 0) {
  48                 b -= a;
  49             }
  50             if (i % 5 == 0) {
  51                 for (int j = 0; j < i; j++) {
  52                     c += a;
  53                 }
  54                 a -= f;
  55             }
  56             b = a ^ c;
  57             if (i % 6 == 0) {
  58                 c--;
  59             } else if (i % 7 == 0) {
  60                 Runtime.getRuntime().totalMemory();
  61             }
  62         }
  63         return a + b + c;
  64     }
  65 
  66     @Test
  67     public void run0() {
  68         runTest("test", 10);
  69     }
  70 
  71     @Test
  72     public void run1() {
  73         runTest("test", 1000);
  74     }
  75 
  76     @Test
  77     public void run2() {
  78         runTest("test", 1);
  79     }
  80 
  81     @Test
  82     public void run3() {
  83         runTest("test", 0);
  84     }
  85 }