view test/runtime/8007320/ConstMethodTest.java @ 10185:d50cc62e94ff

8012715: G1: GraphKit accesses PtrQueue::_index as int but is size_t Summary: In graphKit INT operations were generated to access PtrQueue::_index which has type size_t. This is 64 bit on 64-bit machines. No problems occur on little endian machines as long as the index fits into 32 bit, but on big endian machines the upper part is read, which is zero. This leads to unnecessary branches to the slow path in the runtime. Reviewed-by: twisti, johnc Contributed-by: Martin Doerr <martin.doerr@sap.com>
author johnc
date Wed, 24 Apr 2013 14:48:43 -0700
parents 927a311d00f9
children a589c78a8811
line wrap: on
line source

/*
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * @test
 * @bug 8007320
 * @summary Test all optional fields in ConstMethod
 * @compile -g -parameters ConstMethodTest.java
 * @run main ConstMethodTest
 */

import java.util.*;
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.io.Serializable;

@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
    public String name();
    public String value();
    public String date() default "today";
}

@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface TypeAnno {
    String value();
}

@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface TypeAnno2 {
    String value();
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@interface Named {
  String value();
}

@Retention(RetentionPolicy.RUNTIME)
@interface ScalarTypesWithDefault {
    byte     b()    default 11;
    short    s()    default 12;
    int      i()    default 13;
    long     l()    default 14;
    char     c()    default 'V';
}

// Some exception class
class OkException extends RuntimeException {};


@MyAnnotation(name="someName", value = "Hello World")
public class ConstMethodTest {

    private static void check(boolean b) {
        if (!b)
            throw new RuntimeException();
    }
    private static void fail(String msg) {
       System.err.println(msg);
       throw new RuntimeException();
    }
    private static void equal(Object x, Object y) {
        if (x == null ? y == null : x.equals(y)) {
        } else {
            fail(x + " not equal to " + y);
        }
    }
    private static final String[] parameter_names = {
        "parameter", "parameter2", "x"
    };

    // Declare a function with everything in it.
    @MyAnnotation(name="someName", value="Hello World")
    static <T> void kitchenSinkFunc(@Named(value="aName") String parameter,
              @Named("bName") String parameter2,
              @ScalarTypesWithDefault T x)
            throws @TypeAnno("RE") @TypeAnno2("RE2") RuntimeException,
                NullPointerException,
                @TypeAnno("AIOOBE") ArrayIndexOutOfBoundsException {
      int i, j, k;
      try {
        System.out.println("calling kitchenSinkFunc " + parameter);
        throw new OkException();  // to see stack trace with line numbers
      } catch (Exception e) {
       e.printStackTrace();
      }
    }

    private static void test1() throws Throwable {
        for (Method m : ConstMethodTest.class.getDeclaredMethods()) {
            if (m.getName().equals("kitchenSinkFunc")) {
                Annotation[][] ann = m.getParameterAnnotations();
                equal(ann.length, 3);
                Annotation foo = ann[0][0];
                Annotation bar = ann[1][0];
                equal(foo.toString(), "@Named(value=aName)");
                equal(bar.toString(), "@Named(value=bName)");
                check(foo.equals(foo));
                check(bar.equals(bar));
                check(! foo.equals(bar));
                // method annotations
                Annotation[] ann2 = m.getAnnotations();
                equal(ann2.length, 1);
                Annotation mann = ann2[0];
                equal(mann.toString(), "@MyAnnotation(date=today, name=someName, value=Hello World)");
                // Test Method parameter names
                Parameter[] parameters = m.getParameters();
                if(parameters == null)
                    throw new Exception("getParameters should never be null");
                for(int i = 0; i < parameters.length; i++) {
                    Parameter p = parameters[i];
                    equal(parameters[i].getName(), parameter_names[i]);
                }
            }
        }
    }

    public static void main(java.lang.String[] unused) throws Throwable {
        // pass 5 so kitchenSinkFunc is instantiated with an int
        kitchenSinkFunc("parameter", "param2", 5);
        test1();
    }
};