jdk/src/share/classes/java/lang/invoke/CountingMethodHandle.java
author jrose
Wed, 18 Jan 2012 17:34:30 -0800
changeset 11535 c248aa7dfe5d
parent 10615 7e211ad476ca
permissions -rw-r--r--
7077803: java.lang.InternalError in java.lang.invoke.MethodHandleNatives.init Summary: Use correct access token for unreflecting MHs where setAccessible(true) Reviewed-by: never, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10615
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     1
/*
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     4
 *
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    10
 *
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    15
 * accompanied this code).
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    16
 *
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    20
 *
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    23
 * questions.
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    24
 */
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    25
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    26
package java.lang.invoke;
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    27
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    28
import static java.lang.invoke.MethodHandleNatives.Constants.*;
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    29
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    30
/**
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    31
 * This method handle is used to optionally provide a count of how
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    32
 * many times it was invoked.
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    33
 *
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    34
 * @author never
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    35
 */
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    36
class CountingMethodHandle extends AdapterMethodHandle {
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    37
    private int vmcount;
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    38
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    39
    private CountingMethodHandle(MethodHandle target) {
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    40
        super(target, target.type(), AdapterMethodHandle.makeConv(OP_RETYPE_ONLY));
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    41
    }
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    42
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    43
    /** Wrap the incoming MethodHandle in a CountingMethodHandle if they are enabled */
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    44
    static MethodHandle wrap(MethodHandle mh) {
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    45
        if (MethodHandleNatives.COUNT_GWT) {
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    46
            return new CountingMethodHandle(mh);
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    47
        }
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    48
        return mh;
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    49
    }
7e211ad476ca 7082631: JSR 292: need profiling support in GWTs
never
parents:
diff changeset
    50
}