Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LibraryVMInterfaceImpl.java « lang « java « classpath - github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 526efde56a100f7a21e5d158fa0ac54efffe7bd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
  Copyright (C) 2004, 2005 Jeroen Frijters

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

  Jeroen Frijters
  jeroen@frijters.net
  
*/

package java.lang;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import ikvm.lang.CIL;

class LibraryVMInterfaceImpl implements ikvm.internal.LibraryVMInterface
{
    public Object loadClass(Object classLoader, String name) throws ClassNotFoundException
    {
        return ((ClassLoader)classLoader).loadClass(name).vmdata;
    }

    public Object newClass(Object wrapper, Object protectionDomain)
    {
        return new Class(wrapper, (java.security.ProtectionDomain)protectionDomain);
    }

    public Object newField(Object clazz, Object wrapper)
    {
        return VMClass.createField((Class)clazz, wrapper);
    }

    public Object newConstructor(Object clazz, Object wrapper)
    {
        return VMClass.createConstructor((Class)clazz, wrapper);
    }

    public Object newMethod(Object clazz, Object wrapper)
    {
        return VMClass.createMethod((Class)clazz, wrapper);
    }

    public Object getWrapperFromClass(Object clazz)
    {
        return ((Class)clazz).vmdata;
    }

    public Object getWrapperFromField(Object field)
    {
        return getWrapperFromField((Field)field);
    }

    private static native Object getWrapperFromField(Field field);
    private static native Object getWrapperFromMethod(Method method);
    private static native Object getWrapperFromConstructor(Constructor constructor);

    public Object getWrapperFromMethodOrConstructor(Object methodOrConstructor)
    {
        if(methodOrConstructor instanceof Method)
        {
            return getWrapperFromMethod((Method)methodOrConstructor);
        }
        else
        {
            return getWrapperFromConstructor((Constructor)methodOrConstructor);
        }
    }

    public Object getSystemClassLoader()
    {
        return ClassLoader.StaticData.systemClassLoader;
    }

    public Object box(Object val)
    {
        if(val instanceof cli.System.Byte)
        {
            return new Byte(CIL.unbox_byte(val));
        }
        else if(val instanceof cli.System.Boolean)
        {
            return new Boolean(CIL.unbox_boolean(val));
        }
        else if(val instanceof cli.System.Int16)
        {
            return new Short(CIL.unbox_short(val));
        }
        else if(val instanceof cli.System.Char)
        {
            return new Character(CIL.unbox_char(val));
        }
        else if(val instanceof cli.System.Int32)
        {
            return new Integer(CIL.unbox_int(val));
        }
        else if(val instanceof cli.System.Single)
        {
            return new Float(CIL.unbox_float(val));
        }
        else if(val instanceof cli.System.Int64)
        {
            return new Long(CIL.unbox_long(val));
        }
        else if(val instanceof cli.System.Double)
        {
            return new Double(CIL.unbox_double(val));
        }
        else
        {
            throw new IllegalArgumentException();
        }
    }
    
    public Object unbox(Object val)
    {
        if(val instanceof Byte)
        {
            return CIL.box_byte(((Byte)val).byteValue());
        }
        else if(val instanceof Boolean)
        {
            return CIL.box_boolean(((Boolean)val).booleanValue());
        }
        else if(val instanceof Short)
        {
            return CIL.box_short(((Short)val).shortValue());
        }
        else if(val instanceof Character)
        {
            return CIL.box_char(((Character)val).charValue());
        }
        else if(val instanceof Integer)
        {
            return CIL.box_int(((Integer)val).intValue());
        }
        else if(val instanceof Float)
        {
            return CIL.box_float(((Float)val).floatValue());
        }
        else if(val instanceof Long)
        {
            return CIL.box_long(((Long)val).longValue());
        }
        else if(val instanceof Double)
        {
            return CIL.box_double(((Double)val).doubleValue());
        }
        else
        {
            throw new IllegalArgumentException();
        }
    }

    public Throwable mapException(Throwable t)
    {
        return ExceptionHelper.MapExceptionFast(t);
    }

    public void printStackTrace(Throwable t)
    {
        t.printStackTrace();
    }

    public void jniWaitUntilLastThread()
    {
        VMThread.jniWaitUntilLastThread();
    }

    public void jniDetach()
    {
        VMThread.jniDetach();
    }

    public void setThreadGroup(Object group)
    {
        VMThread.setThreadGroup((ThreadGroup)group);
    }

    public native Object newDirectByteBuffer(cli.System.IntPtr address, int capacity);
    public native cli.System.IntPtr getDirectBufferAddress(Object buffer);
    
    public int getDirectBufferCapacity(Object buffer)
    {
        return ((java.nio.Buffer)buffer).capacity();
    }

    public void setProperties(cli.System.Collections.Hashtable props)
    {
        gnu.classpath.VMSystemProperties.props = props;
    }

    public boolean runFinalizersOnExit()
    {
        return VMRuntime.runFinalizersOnExitFlag;
    }

    public Throwable newIllegalAccessError(String msg)
    {
        return new IllegalAccessError(msg);
    }

    public Throwable newIllegalAccessException(String msg)
    {
        return new IllegalAccessException(msg);
    }

    public Throwable newIncompatibleClassChangeError(String msg)
    {
        return new IncompatibleClassChangeError(msg);
    }

    public Throwable newLinkageError(String msg)
    {
        return new LinkageError(msg);
    }

    public Throwable newVerifyError(String msg)
    {
        return new VerifyError(msg);
    }

    public Throwable newClassCircularityError(String msg)
    {
        return new ClassCircularityError(msg);
    }

    public Throwable newClassFormatError(String msg)
    {
        return new ClassFormatError(msg);
    }

    public Throwable newUnsupportedClassVersionError(String msg)
    {
        return new UnsupportedClassVersionError(msg);
    }

    public Throwable newNoClassDefFoundError(String msg)
    {
        return new NoClassDefFoundError(msg);
    }

    public Throwable newClassNotFoundException(String msg)
    {
        return new ClassNotFoundException(msg);
    }

    public Throwable newUnsatisfiedLinkError(String msg)
    {
        return new UnsatisfiedLinkError(msg);
    }

    public Throwable newIllegalArgumentException(String msg)
    {
        return new IllegalArgumentException(msg);
    }

    public Throwable newNegativeArraySizeException()
    {
        return new NegativeArraySizeException();
    }

    public Throwable newArrayStoreException()
    {
        return new ArrayStoreException();
    }

    public Throwable newIndexOutOfBoundsException(String msg)
    {
        return new IndexOutOfBoundsException(msg);
    }

    public Throwable newStringIndexOutOfBoundsException()
    {
        return new StringIndexOutOfBoundsException();
    }

    public Throwable newInvocationTargetException(Throwable t)
    {
        return new InvocationTargetException(t);
    }

    public Throwable newUnknownHostException(String msg)
    {
        return new java.net.UnknownHostException(msg);
    }

    public Throwable newArrayIndexOutOfBoundsException()
    {
        return new ArrayIndexOutOfBoundsException();
    }

    public Throwable newNumberFormatException(String msg)
    {
        return new NumberFormatException(msg);
    }

    public Throwable newNullPointerException()
    {
        return new NullPointerException();
    }

    public Throwable newClassCastException(String msg)
    {
        return new ClassCastException(msg);
    }

    public Throwable newNoSuchFieldError(String msg)
    {
        return new NoSuchFieldError(msg);
    }

    public Throwable newNoSuchMethodError(String msg)
    {
        return new NoSuchMethodError(msg);
    }

    public Throwable newInstantiationError(String msg)
    {
        return new InstantiationError(msg);
    }

    public Throwable newInstantiationException(String msg)
    {
        return new InstantiationException(msg);
    }

    public Throwable newInterruptedException()
    {
        return new InterruptedException();
    }

    public Throwable newIllegalMonitorStateException()
    {
        return new IllegalMonitorStateException();
    }
}