1 /* |
1 /* |
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
30 * An {@code invokedynamic} instruction linked to a {@code ConstantCallSite} is permanently |
30 * An {@code invokedynamic} instruction linked to a {@code ConstantCallSite} is permanently |
31 * bound to the call site's target. |
31 * bound to the call site's target. |
32 * @author John Rose, JSR 292 EG |
32 * @author John Rose, JSR 292 EG |
33 */ |
33 */ |
34 public class ConstantCallSite extends CallSite { |
34 public class ConstantCallSite extends CallSite { |
35 /** Create a call site with a permanent target. |
35 /** |
|
36 * Creates a call site with a permanent target. |
|
37 * @param target the target to be permanently associated with this call site |
36 * @throws NullPointerException if the proposed target is null |
38 * @throws NullPointerException if the proposed target is null |
37 */ |
39 */ |
38 public ConstantCallSite(MethodHandle target) { |
40 public ConstantCallSite(MethodHandle target) { |
39 super(target); |
41 super(target); |
40 } |
42 } |
|
43 |
41 /** |
44 /** |
42 * Throw an {@link UnsupportedOperationException}, because this kind of call site cannot change its target. |
45 * Returns the target method of the call site, which behaves |
|
46 * like a {@code final} field of the {@code ConstantCallSite}. |
|
47 * That is, the the target is always the original value passed |
|
48 * to the constructor call which created this instance. |
|
49 * |
|
50 * @return the immutable linkage state of this call site, a constant method handle |
|
51 * @throws UnsupportedOperationException because this kind of call site cannot change its target |
|
52 */ |
|
53 @Override public final MethodHandle getTarget() { |
|
54 return target; |
|
55 } |
|
56 |
|
57 /** |
|
58 * Always throws an {@link UnsupportedOperationException}. |
|
59 * This kind of call site cannot change its target. |
|
60 * @param ignore a new target proposed for the call site, which is ignored |
|
61 * @throws UnsupportedOperationException because this kind of call site cannot change its target |
43 */ |
62 */ |
44 @Override public final void setTarget(MethodHandle ignore) { |
63 @Override public final void setTarget(MethodHandle ignore) { |
45 throw new UnsupportedOperationException("ConstantCallSite"); |
64 throw new UnsupportedOperationException("ConstantCallSite"); |
46 } |
65 } |
|
66 |
|
67 /** |
|
68 * Returns this call site's permanent target. |
|
69 * Since that target will never change, this is a correct implementation |
|
70 * of {@link CallSite#dynamicInvoker CallSite.dynamicInvoker}. |
|
71 * @return the immutable linkage state of this call site, a constant method handle |
|
72 */ |
|
73 @Override |
|
74 public final MethodHandle dynamicInvoker() { |
|
75 return getTarget(); |
|
76 } |
47 } |
77 } |