IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ClassFile.ConstantPoolItemMethodHandle.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2015 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24
25using IKVM.ByteCode;
26using IKVM.ByteCode.Decoding;
27
28namespace IKVM.Runtime
29{
30
31 sealed partial class ClassFile
32 {
33
37 internal sealed class ConstantPoolItemMethodHandle : ConstantPoolItem
38 {
39
40 readonly MethodHandleConstantData data;
41 ConstantPoolItemFMI cpi;
42
48 internal ConstantPoolItemMethodHandle(RuntimeContext context, MethodHandleConstantData data) :
49 base(context)
50 {
51 this.data = data;
52 }
53
55 public override ConstantType GetConstantType() => ConstantType.MethodHandle;
56
58 public override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileParseOptions options)
59 {
60 switch (data.Kind)
61 {
62 case MethodHandleKind.GetField:
63 case MethodHandleKind.GetStatic:
64 case MethodHandleKind.PutField:
65 case MethodHandleKind.PutStatic:
66 cpi = classFile.GetConstantPoolItem(data.Reference) as ConstantPoolItemFieldref;
67 break;
68 case MethodHandleKind.InvokeSpecial:
69 case MethodHandleKind.InvokeVirtual:
70 case MethodHandleKind.InvokeStatic:
71 case MethodHandleKind.NewInvokeSpecial:
72 cpi = classFile.GetConstantPoolItem(data.Reference) as ConstantPoolItemMethodref;
73 if (cpi == null && classFile.MajorVersion >= 52 && (data.Kind is MethodHandleKind.InvokeStatic or MethodHandleKind.InvokeSpecial))
74 goto case MethodHandleKind.InvokeInterface;
75 break;
76 case MethodHandleKind.InvokeInterface:
77 cpi = classFile.GetConstantPoolItem(data.Reference) as ConstantPoolItemInterfaceMethodref;
78 break;
79 }
80
81 if (cpi == null)
82 throw new ClassFormatError("Invalid constant pool item MethodHandle");
83
84 if (ReferenceEquals(cpi.Name, StringConstants.INIT) && data.Kind != MethodHandleKind.NewInvokeSpecial)
85 throw new ClassFormatError("Bad method name");
86 }
87
89 public override void MarkLinkRequired()
90 {
91 cpi.MarkLinkRequired();
92 }
93
95 public override void Link(RuntimeJavaType thisType, LoadMode mode)
96 {
97 cpi.Link(thisType, mode);
98 }
99
100 public string Class => cpi.Class;
101
102 public string Name => cpi.Name;
103
104 public string Signature => cpi.Signature;
105
106 public ConstantPoolItemFMI MemberConstantPoolItem => cpi;
107
108 public MethodHandleKind Kind => data.Kind;
109
110 public RuntimeJavaMember Member => cpi.GetMember();
111
112 public RuntimeJavaType GetClassType()
113 {
114 return cpi.GetClassType();
115 }
116
117 }
118
119 }
120
121}
global::java.lang.Class Class
global::java.lang.invoke.LambdaForm.Name Name