1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoader.hpp"
27 #include "classfile/javaAssertions.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "gc_interface/collectedHeap.inline.hpp"
33 #include "memory/oopFactory.hpp"
34 #include "memory/universe.inline.hpp"
35 #include "oops/fieldStreams.hpp"
36 #include "oops/instanceKlass.hpp"
37 #include "oops/objArrayKlass.hpp"
38 #include "prims/jvm.h"
39 #include "prims/jvm_misc.hpp"
40 #include "prims/jvmtiExport.hpp"
41 #include "prims/jvmtiThreadState.hpp"
42 #include "prims/nativeLookup.hpp"
43 #include "prims/privilegedStack.hpp"
44 #include "runtime/arguments.hpp"
45 #include "runtime/dtraceJSDT.hpp"
46 #include "runtime/handles.inline.hpp"
47 #include "runtime/init.hpp"
48 #include "runtime/interfaceSupport.hpp"
49 #include "runtime/java.hpp"
50 #include "runtime/javaCalls.hpp"
51 #include "runtime/jfieldIDWorkaround.hpp"
52 #include "runtime/os.hpp"
53 #include "runtime/perfData.hpp"
54 #include "runtime/reflection.hpp"
55 #include "runtime/vframe.hpp"
56 #include "runtime/vm_operations.hpp"
57 #include "services/attachListener.hpp"
2275 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2276 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2277 memcpy(code, methodOop(method)->code_base(), methodOop(method)->code_size());
2278 JVM_END
2279
2280
2281 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
2282 JVMWrapper("JVM_GetMethodIxByteCodeLength");
2283 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2284 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2285 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2286 return methodOop(method)->code_size();
2287 JVM_END
2288
2289
2290 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
2291 JVMWrapper("JVM_GetMethodIxExceptionTableEntry");
2292 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2293 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2294 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2295 typeArrayOop extable = methodOop(method)->exception_table();
2296 entry->start_pc = extable->int_at(entry_index * 4);
2297 entry->end_pc = extable->int_at(entry_index * 4 + 1);
2298 entry->handler_pc = extable->int_at(entry_index * 4 + 2);
2299 entry->catchType = extable->int_at(entry_index * 4 + 3);
2300 JVM_END
2301
2302
2303 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
2304 JVMWrapper("JVM_GetMethodIxExceptionTableLength");
2305 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2306 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2307 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2308 return methodOop(method)->exception_table()->length() / 4;
2309 JVM_END
2310
2311
2312 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
2313 JVMWrapper("JVM_GetMethodIxModifiers");
2314 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2315 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2316 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2317 return methodOop(method)->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
2318 JVM_END
2319
2320
2321 JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
2322 JVMWrapper("JVM_GetFieldIxModifiers");
2323 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2324 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2325 return instanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS;
2326 JVM_END
2327
2328
2395 constantPoolOop cp = instanceKlass::cast(k)->constants();
2396 switch (cp->tag_at(cp_index).value()) {
2397 case JVM_CONSTANT_Fieldref:
2398 return cp->uncached_name_ref_at(cp_index)->as_utf8();
2399 default:
2400 fatal("JVM_GetCPFieldNameUTF: illegal constant");
2401 }
2402 ShouldNotReachHere();
2403 return NULL;
2404 JVM_END
2405
2406
2407 JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2408 JVMWrapper("JVM_GetCPMethodNameUTF");
2409 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2410 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2411 constantPoolOop cp = instanceKlass::cast(k)->constants();
2412 switch (cp->tag_at(cp_index).value()) {
2413 case JVM_CONSTANT_InterfaceMethodref:
2414 case JVM_CONSTANT_Methodref:
2415 case JVM_CONSTANT_NameAndType: // for invokedynamic
2416 return cp->uncached_name_ref_at(cp_index)->as_utf8();
2417 default:
2418 fatal("JVM_GetCPMethodNameUTF: illegal constant");
2419 }
2420 ShouldNotReachHere();
2421 return NULL;
2422 JVM_END
2423
2424
2425 JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
2426 JVMWrapper("JVM_GetCPMethodSignatureUTF");
2427 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2428 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2429 constantPoolOop cp = instanceKlass::cast(k)->constants();
2430 switch (cp->tag_at(cp_index).value()) {
2431 case JVM_CONSTANT_InterfaceMethodref:
2432 case JVM_CONSTANT_Methodref:
2433 case JVM_CONSTANT_NameAndType: // for invokedynamic
2434 return cp->uncached_signature_ref_at(cp_index)->as_utf8();
2435 default:
2436 fatal("JVM_GetCPMethodSignatureUTF: illegal constant");
2437 }
2438 ShouldNotReachHere();
2439 return NULL;
2440 JVM_END
2441
2442
2443 JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
2444 JVMWrapper("JVM_GetCPFieldSignatureUTF");
2445 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2446 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2447 constantPoolOop cp = instanceKlass::cast(k)->constants();
2448 switch (cp->tag_at(cp_index).value()) {
2449 case JVM_CONSTANT_Fieldref:
2450 return cp->uncached_signature_ref_at(cp_index)->as_utf8();
2451 default:
2452 fatal("JVM_GetCPFieldSignatureUTF: illegal constant");
2453 }
2638
2639 JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length))
2640 JVMWrapper3("JVM_SetLength (0x%x, %Ld)", fd, length);
2641 return os::ftruncate(fd, length);
2642 JVM_END
2643
2644
2645 JVM_LEAF(jint, JVM_Sync(jint fd))
2646 JVMWrapper2("JVM_Sync (0x%x)", fd);
2647 //%note jvm_r6
2648 return os::fsync(fd);
2649 JVM_END
2650
2651
2652 // Printing support //////////////////////////////////////////////////
2653 extern "C" {
2654
2655 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
2656 // see bug 4399518, 4417214
2657 if ((intptr_t)count <= 0) return -1;
2658 return vsnprintf(str, count, fmt, args);
2659 }
2660
2661
2662 int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
2663 va_list args;
2664 int len;
2665 va_start(args, fmt);
2666 len = jio_vsnprintf(str, count, fmt, args);
2667 va_end(args);
2668 return len;
2669 }
2670
2671
2672 int jio_fprintf(FILE* f, const char *fmt, ...) {
2673 int len;
2674 va_list args;
2675 va_start(args, fmt);
2676 len = jio_vfprintf(f, fmt, args);
2677 va_end(args);
2678 return len;
|
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoader.hpp"
27 #include "classfile/javaAssertions.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "gc_interface/collectedHeap.inline.hpp"
33 #include "memory/oopFactory.hpp"
34 #include "memory/universe.inline.hpp"
35 #include "oops/fieldStreams.hpp"
36 #include "oops/instanceKlass.hpp"
37 #include "oops/objArrayKlass.hpp"
38 #include "oops/methodOop.hpp"
39 #include "prims/jvm.h"
40 #include "prims/jvm_misc.hpp"
41 #include "prims/jvmtiExport.hpp"
42 #include "prims/jvmtiThreadState.hpp"
43 #include "prims/nativeLookup.hpp"
44 #include "prims/privilegedStack.hpp"
45 #include "runtime/arguments.hpp"
46 #include "runtime/dtraceJSDT.hpp"
47 #include "runtime/handles.inline.hpp"
48 #include "runtime/init.hpp"
49 #include "runtime/interfaceSupport.hpp"
50 #include "runtime/java.hpp"
51 #include "runtime/javaCalls.hpp"
52 #include "runtime/jfieldIDWorkaround.hpp"
53 #include "runtime/os.hpp"
54 #include "runtime/perfData.hpp"
55 #include "runtime/reflection.hpp"
56 #include "runtime/vframe.hpp"
57 #include "runtime/vm_operations.hpp"
58 #include "services/attachListener.hpp"
2276 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2277 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2278 memcpy(code, methodOop(method)->code_base(), methodOop(method)->code_size());
2279 JVM_END
2280
2281
2282 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
2283 JVMWrapper("JVM_GetMethodIxByteCodeLength");
2284 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2285 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2286 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2287 return methodOop(method)->code_size();
2288 JVM_END
2289
2290
2291 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
2292 JVMWrapper("JVM_GetMethodIxExceptionTableEntry");
2293 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2294 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2295 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2296 ExceptionTable extable((methodOop(method)));
2297 entry->start_pc = extable.start_pc(entry_index);
2298 entry->end_pc = extable.end_pc(entry_index);
2299 entry->handler_pc = extable.handler_pc(entry_index);
2300 entry->catchType = extable.catch_type_index(entry_index);
2301 JVM_END
2302
2303
2304 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
2305 JVMWrapper("JVM_GetMethodIxExceptionTableLength");
2306 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2307 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2308 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2309 return methodOop(method)->exception_table_length();
2310 JVM_END
2311
2312
2313 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
2314 JVMWrapper("JVM_GetMethodIxModifiers");
2315 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2316 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2317 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2318 return methodOop(method)->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
2319 JVM_END
2320
2321
2322 JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
2323 JVMWrapper("JVM_GetFieldIxModifiers");
2324 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2325 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2326 return instanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS;
2327 JVM_END
2328
2329
2396 constantPoolOop cp = instanceKlass::cast(k)->constants();
2397 switch (cp->tag_at(cp_index).value()) {
2398 case JVM_CONSTANT_Fieldref:
2399 return cp->uncached_name_ref_at(cp_index)->as_utf8();
2400 default:
2401 fatal("JVM_GetCPFieldNameUTF: illegal constant");
2402 }
2403 ShouldNotReachHere();
2404 return NULL;
2405 JVM_END
2406
2407
2408 JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2409 JVMWrapper("JVM_GetCPMethodNameUTF");
2410 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2411 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2412 constantPoolOop cp = instanceKlass::cast(k)->constants();
2413 switch (cp->tag_at(cp_index).value()) {
2414 case JVM_CONSTANT_InterfaceMethodref:
2415 case JVM_CONSTANT_Methodref:
2416 return cp->uncached_name_ref_at(cp_index)->as_utf8();
2417 default:
2418 fatal("JVM_GetCPMethodNameUTF: illegal constant");
2419 }
2420 ShouldNotReachHere();
2421 return NULL;
2422 JVM_END
2423
2424
2425 JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
2426 JVMWrapper("JVM_GetCPMethodSignatureUTF");
2427 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2428 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2429 constantPoolOop cp = instanceKlass::cast(k)->constants();
2430 switch (cp->tag_at(cp_index).value()) {
2431 case JVM_CONSTANT_InterfaceMethodref:
2432 case JVM_CONSTANT_Methodref:
2433 return cp->uncached_signature_ref_at(cp_index)->as_utf8();
2434 default:
2435 fatal("JVM_GetCPMethodSignatureUTF: illegal constant");
2436 }
2437 ShouldNotReachHere();
2438 return NULL;
2439 JVM_END
2440
2441
2442 JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
2443 JVMWrapper("JVM_GetCPFieldSignatureUTF");
2444 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2445 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2446 constantPoolOop cp = instanceKlass::cast(k)->constants();
2447 switch (cp->tag_at(cp_index).value()) {
2448 case JVM_CONSTANT_Fieldref:
2449 return cp->uncached_signature_ref_at(cp_index)->as_utf8();
2450 default:
2451 fatal("JVM_GetCPFieldSignatureUTF: illegal constant");
2452 }
2637
2638 JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length))
2639 JVMWrapper3("JVM_SetLength (0x%x, %Ld)", fd, length);
2640 return os::ftruncate(fd, length);
2641 JVM_END
2642
2643
2644 JVM_LEAF(jint, JVM_Sync(jint fd))
2645 JVMWrapper2("JVM_Sync (0x%x)", fd);
2646 //%note jvm_r6
2647 return os::fsync(fd);
2648 JVM_END
2649
2650
2651 // Printing support //////////////////////////////////////////////////
2652 extern "C" {
2653
2654 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
2655 // see bug 4399518, 4417214
2656 if ((intptr_t)count <= 0) return -1;
2657
2658 int result = vsnprintf(str, count, fmt, args);
2659 // Note: on truncation vsnprintf(3) on Unix returns number of
2660 // characters which would have been written had the buffer been large
2661 // enough; on Windows, it returns -1. We handle both cases here and
2662 // always return -1, and perform null termination.
2663 if ((result > 0 && (size_t)result >= count) || result == -1) {
2664 str[count - 1] = '\0';
2665 result = -1;
2666 }
2667
2668 return result;
2669 }
2670
2671
2672 int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
2673 va_list args;
2674 int len;
2675 va_start(args, fmt);
2676 len = jio_vsnprintf(str, count, fmt, args);
2677 va_end(args);
2678 return len;
2679 }
2680
2681
2682 int jio_fprintf(FILE* f, const char *fmt, ...) {
2683 int len;
2684 va_list args;
2685 va_start(args, fmt);
2686 len = jio_vfprintf(f, fmt, args);
2687 va_end(args);
2688 return len;
|