001/* 002 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023// Checkstyle: stop 024 025package com.oracle.graal.jtt.hotpath; 026 027import org.junit.*; 028 029import com.oracle.graal.jtt.*; 030 031/* 032 */ 033public class HP_invoke01 extends JTTTest { 034 035 private static int sum; 036 037 public static int test(int count) { 038 sum = 0; 039 final Instruction[] instructions = new Instruction[]{new Instruction.Add(), new Instruction.Sub(), new Instruction.Mul(), new Instruction.Div()}; 040 final Visitor v = new Visitor(); 041 for (int i = 0; i < count; i++) { 042 instructions[i % 4].accept(v); 043 } 044 return sum; 045 } 046 047 public static abstract class Instruction { 048 049 public abstract void accept(Visitor v); 050 051 public static abstract class Binary extends Instruction { 052 053 } 054 055 public static class Add extends Binary { 056 057 @Override 058 public void accept(Visitor v) { 059 v.visit(this); 060 } 061 } 062 063 public static class Sub extends Binary { 064 065 @Override 066 public void accept(Visitor v) { 067 v.visit(this); 068 } 069 } 070 071 public static class Mul extends Binary { 072 073 @Override 074 public void accept(Visitor v) { 075 v.visit(this); 076 } 077 } 078 079 public static class Div extends Binary { 080 081 @Override 082 public void accept(Visitor v) { 083 v.visit(this); 084 } 085 } 086 } 087 088 @SuppressWarnings("unused") 089 public static class Visitor { 090 091 public void visit(Instruction.Add i) { 092 sum += 7; 093 } 094 095 public void visit(Instruction.Sub i) { 096 sum += 194127; 097 } 098 099 public void visit(Instruction.Mul i) { 100 sum += 18991; 101 } 102 103 public void visit(Instruction.Div i) { 104 sum += 91823; 105 } 106 } 107 108 @Test 109 public void run0() throws Throwable { 110 runTest("test", 40); 111 } 112 113 @Test 114 public void run1() throws Throwable { 115 runTest("test", 80); 116 } 117 118}