IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeManagedJavaType.ByRefJavaMethod.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*/
24using System;
25
26using IKVM.Attributes;
27
28#if IMPORTER || EXPORTER
29using IKVM.Reflection;
31
32using Type = IKVM.Reflection.Type;
33#else
34using System.Reflection;
35using System.Reflection.Emit;
36#endif
37
38namespace IKVM.Runtime
39{
40
41 sealed partial class RuntimeManagedJavaType
42 {
43
44 sealed class ByRefJavaMethod : RuntimeSmartJavaMethod
45 {
46
47#if !IMPORTER
48 readonly bool[] byrefs;
49#endif
50 readonly Type[] args;
51
65 internal ByRefJavaMethod(Type[] args, bool[] byrefs, RuntimeJavaType declaringType, string name, string sig, MethodBase method, RuntimeJavaType returnType, RuntimeJavaType[] parameterTypes, Modifiers modifiers, bool hideFromReflection) :
66 base(declaringType, name, sig, method, returnType, parameterTypes, modifiers, hideFromReflection ? MemberFlags.HideFromReflection : MemberFlags.None)
67 {
68 this.args = args;
69#if !IMPORTER
70 this.byrefs = byrefs;
71#endif
72 }
73
74#if EMITTERS
75 protected override void CallImpl(CodeEmitter ilgen)
76 {
77 ConvertByRefArgs(ilgen);
78 ilgen.Emit(OpCodes.Call, GetMethod());
79 }
80
81 protected override void CallvirtImpl(CodeEmitter ilgen)
82 {
83 ConvertByRefArgs(ilgen);
84 ilgen.Emit(OpCodes.Callvirt, GetMethod());
85 }
86
87 protected override void NewobjImpl(CodeEmitter ilgen)
88 {
89 ConvertByRefArgs(ilgen);
90 ilgen.Emit(OpCodes.Newobj, GetMethod());
91 }
92
93 void ConvertByRefArgs(CodeEmitter ilgen)
94 {
95 var locals = new CodeEmitterLocal[args.Length];
96 for (int i = args.Length - 1; i >= 0; i--)
97 {
98 var type = args[i];
99 if (type.IsByRef)
100 type = RuntimeArrayJavaType.MakeArrayType(type.GetElementType(), 1);
101
102 locals[i] = ilgen.DeclareLocal(type);
103 ilgen.Emit(OpCodes.Stloc, locals[i]);
104 }
105
106 for (int i = 0; i < args.Length; i++)
107 {
108 ilgen.Emit(OpCodes.Ldloc, locals[i]);
109 if (args[i].IsByRef)
110 {
111 ilgen.Emit(OpCodes.Ldc_I4_0);
112 ilgen.Emit(OpCodes.Ldelema, args[i].GetElementType());
113 }
114 }
115 }
116
117#endif
118
119 }
120
121 }
122
123}
IKVM.Reflection.Type Type
IKVM.Reflection.MethodBase MethodBase
MemberFlags
Describes various options applied to a member.
@ HideFromReflection
Member should be hidden from Java reflection.