1 /* 2 * Copyright (c) 1997, 2015, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef _JAVASOFT_JVM_H_ 27 #define _JAVASOFT_JVM_H_ 28 29 #include <sys/stat.h> 30 31 #include "jni.h" 32 #include "jvm_md.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /* 39 * This file contains additional functions exported from the VM. 40 * These functions are complementary to the standard JNI support. 41 * There are three parts to this file: 42 * 43 * First, this file contains the VM-related functions needed by native 44 * libraries in the standard Java API. For example, the java.lang.Object 45 * class needs VM-level functions that wait for and notify monitors. 46 * 47 * Second, this file contains the functions and constant definitions 48 * needed by the byte code verifier and class file format checker. 49 * These functions allow the verifier and format checker to be written 50 * in a VM-independent way. 51 * 52 * Third, this file contains various I/O and nerwork operations needed 53 * by the standard Java I/O and network APIs. 54 */ 55 56 /* 57 * Bump the version number when either of the following happens: 58 * 59 * 1. There is a change in JVM_* functions. 60 * 61 * 2. There is a change in the contract between VM and Java classes. 62 * For example, if the VM relies on a new private field in Thread 63 * class. 64 */ 65 66 #define JVM_INTERFACE_VERSION 4 67 68 JNIEXPORT jint JNICALL 69 JVM_GetInterfaceVersion(void); 70 71 /************************************************************************* 72 PART 1: Functions for Native Libraries 73 ************************************************************************/ 74 /* 75 * java.lang.Object 76 */ 77 JNIEXPORT jint JNICALL 78 JVM_IHashCode(JNIEnv *env, jobject obj); 79 80 JNIEXPORT void JNICALL 81 JVM_MonitorWait(JNIEnv *env, jobject obj, jlong ms); 82 83 JNIEXPORT void JNICALL 84 JVM_MonitorNotify(JNIEnv *env, jobject obj); 85 86 JNIEXPORT void JNICALL 87 JVM_MonitorNotifyAll(JNIEnv *env, jobject obj); 88 89 JNIEXPORT jobject JNICALL 90 JVM_Clone(JNIEnv *env, jobject obj); 91 92 /* 93 * java.lang.String 94 */ 95 JNIEXPORT jstring JNICALL 96 JVM_InternString(JNIEnv *env, jstring str); 97 98 /* 99 * java.lang.System 100 */ 101 JNIEXPORT jlong JNICALL 102 JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored); 103 104 JNIEXPORT jlong JNICALL 105 JVM_NanoTime(JNIEnv *env, jclass ignored); 106 107 JNIEXPORT jlong JNICALL 108 JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs); 109 110 JNIEXPORT void JNICALL 111 JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, 112 jobject dst, jint dst_pos, jint length); 113 114 JNIEXPORT jobject JNICALL 115 JVM_InitProperties(JNIEnv *env, jobject p); 116 117 118 /* 119 * java.lang.Runtime 120 */ 121 JNIEXPORT void JNICALL 122 JVM_Halt(jint code); 123 124 JNIEXPORT void JNICALL 125 JVM_GC(void); 126 127 /* Returns the number of real-time milliseconds that have elapsed since the 128 * least-recently-inspected heap object was last inspected by the garbage 129 * collector. 130 * 131 * For simple stop-the-world collectors this value is just the time 132 * since the most recent collection. For generational collectors it is the 133 * time since the oldest generation was most recently collected. Other 134 * collectors are free to return a pessimistic estimate of the elapsed time, or 135 * simply the time since the last full collection was performed. 136 * 137 * Note that in the presence of reference objects, a given object that is no 138 * longer strongly reachable may have to be inspected multiple times before it 139 * can be reclaimed. 140 */ 141 JNIEXPORT jlong JNICALL 142 JVM_MaxObjectInspectionAge(void); 143 144 JNIEXPORT jlong JNICALL 145 JVM_TotalMemory(void); 146 147 JNIEXPORT jlong JNICALL 148 JVM_FreeMemory(void); 149 150 JNIEXPORT jlong JNICALL 151 JVM_MaxMemory(void); 152 153 JNIEXPORT jint JNICALL 154 JVM_ActiveProcessorCount(void); 155 156 JNIEXPORT void * JNICALL 157 JVM_LoadLibrary(const char *name); 158 159 JNIEXPORT void JNICALL 160 JVM_UnloadLibrary(void * handle); 161 162 JNIEXPORT void * JNICALL 163 JVM_FindLibraryEntry(void *handle, const char *name); 164 165 JNIEXPORT jboolean JNICALL 166 JVM_IsSupportedJNIVersion(jint version); 167 168 /* 169 * java.lang.Throwable 170 */ 171 JNIEXPORT void JNICALL 172 JVM_FillInStackTrace(JNIEnv *env, jobject throwable); 173 174 JNIEXPORT jint JNICALL 175 JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable); 176 177 JNIEXPORT jobject JNICALL 178 JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index); 179 180 /* 181 * java.lang.Thread 182 */ 183 JNIEXPORT void JNICALL 184 JVM_StartThread(JNIEnv *env, jobject thread); 185 186 JNIEXPORT void JNICALL 187 JVM_StopThread(JNIEnv *env, jobject thread, jobject exception); 188 189 JNIEXPORT jboolean JNICALL 190 JVM_IsThreadAlive(JNIEnv *env, jobject thread); 191 192 JNIEXPORT void JNICALL 193 JVM_SuspendThread(JNIEnv *env, jobject thread); 194 195 JNIEXPORT void JNICALL 196 JVM_ResumeThread(JNIEnv *env, jobject thread); 197 198 JNIEXPORT void JNICALL 199 JVM_SetThreadPriority(JNIEnv *env, jobject thread, jint prio); 200 201 JNIEXPORT void JNICALL 202 JVM_Yield(JNIEnv *env, jclass threadClass); 203 204 JNIEXPORT void JNICALL 205 JVM_Sleep(JNIEnv *env, jclass threadClass, jlong millis); 206 207 JNIEXPORT jobject JNICALL 208 JVM_CurrentThread(JNIEnv *env, jclass threadClass); 209 210 JNIEXPORT jint JNICALL 211 JVM_CountStackFrames(JNIEnv *env, jobject thread); 212 213 JNIEXPORT void JNICALL 214 JVM_Interrupt(JNIEnv *env, jobject thread); 215 216 JNIEXPORT jboolean JNICALL 217 JVM_IsInterrupted(JNIEnv *env, jobject thread, jboolean clearInterrupted); 218 219 JNIEXPORT jboolean JNICALL 220 JVM_HoldsLock(JNIEnv *env, jclass threadClass, jobject obj); 221 222 JNIEXPORT void JNICALL 223 JVM_DumpAllStacks(JNIEnv *env, jclass unused); 224 225 JNIEXPORT jobjectArray JNICALL 226 JVM_GetAllThreads(JNIEnv *env, jclass dummy); 227 228 JNIEXPORT void JNICALL 229 JVM_SetNativeThreadName(JNIEnv *env, jobject jthread, jstring name); 230 231 /* getStackTrace() and getAllStackTraces() method */ 232 JNIEXPORT jobjectArray JNICALL 233 JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads); 234 235 /* 236 * java.lang.SecurityManager 237 */ 238 JNIEXPORT jclass JNICALL 239 JVM_CurrentLoadedClass(JNIEnv *env); 240 241 JNIEXPORT jobject JNICALL 242 JVM_CurrentClassLoader(JNIEnv *env); 243 244 JNIEXPORT jobjectArray JNICALL 245 JVM_GetClassContext(JNIEnv *env); 246 247 JNIEXPORT jint JNICALL 248 JVM_ClassDepth(JNIEnv *env, jstring name); 249 250 JNIEXPORT jint JNICALL 251 JVM_ClassLoaderDepth(JNIEnv *env); 252 253 /* 254 * java.lang.Package 255 */ 256 JNIEXPORT jstring JNICALL 257 JVM_GetSystemPackage(JNIEnv *env, jstring name); 258 259 JNIEXPORT jobjectArray JNICALL 260 JVM_GetSystemPackages(JNIEnv *env); 261 262 /* 263 * java.io.ObjectInputStream 264 */ 265 JNIEXPORT jobject JNICALL 266 JVM_LatestUserDefinedLoader(JNIEnv *env); 267 268 /* 269 * java.lang.reflect.Array 270 */ 271 JNIEXPORT jint JNICALL 272 JVM_GetArrayLength(JNIEnv *env, jobject arr); 273 274 JNIEXPORT jobject JNICALL 275 JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index); 276 277 JNIEXPORT jvalue JNICALL 278 JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode); 279 280 JNIEXPORT void JNICALL 281 JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val); 282 283 JNIEXPORT void JNICALL 284 JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, 285 unsigned char vCode); 286 287 JNIEXPORT jobject JNICALL 288 JVM_NewArray(JNIEnv *env, jclass eltClass, jint length); 289 290 JNIEXPORT jobject JNICALL 291 JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim); 292 293 /* 294 * java.lang.Class and java.lang.ClassLoader 295 */ 296 297 #define JVM_CALLER_DEPTH -1 298 299 /* 300 * Returns the immediate caller class of the native method invoking 301 * JVM_GetCallerClass. The Method.invoke and other frames due to 302 * reflection machinery are skipped. 303 * 304 * The depth parameter must be -1 (JVM_DEPTH). The caller is expected 305 * to be marked with sun.reflect.CallerSensitive. The JVM will throw 306 * an error if it is not marked propertly. 307 */ 308 JNIEXPORT jclass JNICALL 309 JVM_GetCallerClass(JNIEnv *env, int depth); 310 311 312 /* 313 * Find primitive classes 314 * utf: class name 315 */ 316 JNIEXPORT jclass JNICALL 317 JVM_FindPrimitiveClass(JNIEnv *env, const char *utf); 318 319 320 /* 321 * Find a class from a boot class loader. Returns NULL if class not found. 322 */ 323 JNIEXPORT jclass JNICALL 324 JVM_FindClassFromBootLoader(JNIEnv *env, const char *name); 325 326 /* 327 * Find a class from a given class loader. Throws ClassNotFoundException. 328 * name: name of class 329 * init: whether initialization is done 330 * loader: class loader to look up the class. This may not be the same as the caller's 331 * class loader. 332 * caller: initiating class. The initiating class may be null when a security 333 * manager is not installed. 334 */ 335 JNIEXPORT jclass JNICALL 336 JVM_FindClassFromCaller(JNIEnv *env, const char *name, jboolean init, 337 jobject loader, jclass caller); 338 339 /* 340 * Find a class from a given class. 341 */ 342 JNIEXPORT jclass JNICALL 343 JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, 344 jclass from); 345 346 /* Find a loaded class cached by the VM */ 347 JNIEXPORT jclass JNICALL 348 JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name); 349 350 /* Define a class */ 351 JNIEXPORT jclass JNICALL 352 JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, 353 jsize len, jobject pd); 354 355 /* Define a class with a source (added in JDK1.5) */ 356 JNIEXPORT jclass JNICALL 357 JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, 358 const jbyte *buf, jsize len, jobject pd, 359 const char *source); 360 361 /* 362 * Reflection support functions 363 */ 364 365 JNIEXPORT jstring JNICALL 366 JVM_GetClassName(JNIEnv *env, jclass cls); 367 368 JNIEXPORT jobjectArray JNICALL 369 JVM_GetClassInterfaces(JNIEnv *env, jclass cls); 370 371 JNIEXPORT jboolean JNICALL 372 JVM_IsInterface(JNIEnv *env, jclass cls); 373 374 JNIEXPORT jobjectArray JNICALL 375 JVM_GetClassSigners(JNIEnv *env, jclass cls); 376 377 JNIEXPORT void JNICALL 378 JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers); 379 380 JNIEXPORT jobject JNICALL 381 JVM_GetProtectionDomain(JNIEnv *env, jclass cls); 382 383 JNIEXPORT jboolean JNICALL 384 JVM_IsArrayClass(JNIEnv *env, jclass cls); 385 386 JNIEXPORT jboolean JNICALL 387 JVM_IsPrimitiveClass(JNIEnv *env, jclass cls); 388 389 JNIEXPORT jint JNICALL 390 JVM_GetClassModifiers(JNIEnv *env, jclass cls); 391 392 JNIEXPORT jobjectArray JNICALL 393 JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass); 394 395 JNIEXPORT jclass JNICALL 396 JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass); 397 398 JNIEXPORT jstring JNICALL 399 JVM_GetSimpleBinaryName(JNIEnv *env, jclass ofClass); 400 401 /* Generics support (JDK 1.5) */ 402 JNIEXPORT jstring JNICALL 403 JVM_GetClassSignature(JNIEnv *env, jclass cls); 404 405 /* Annotations support (JDK 1.5) */ 406 JNIEXPORT jbyteArray JNICALL 407 JVM_GetClassAnnotations(JNIEnv *env, jclass cls); 408 409 /* Type use annotations support (JDK 1.8) */ 410 411 JNIEXPORT jbyteArray JNICALL 412 JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls); 413 414 JNIEXPORT jbyteArray JNICALL 415 JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field); 416 417 JNIEXPORT jbyteArray JNICALL 418 JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method); 419 420 /* 421 * New (JDK 1.4) reflection implementation 422 */ 423 424 JNIEXPORT jobjectArray JNICALL 425 JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly); 426 427 JNIEXPORT jobjectArray JNICALL 428 JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly); 429 430 JNIEXPORT jobjectArray JNICALL 431 JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly); 432 433 /* Differs from JVM_GetClassModifiers in treatment of inner classes. 434 This returns the access flags for the class as specified in the 435 class file rather than searching the InnerClasses attribute (if 436 present) to find the source-level access flags. Only the values of 437 the low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be 438 valid. */ 439 JNIEXPORT jint JNICALL 440 JVM_GetClassAccessFlags(JNIEnv *env, jclass cls); 441 442 /* The following two reflection routines are still needed due to startup time issues */ 443 /* 444 * java.lang.reflect.Method 445 */ 446 JNIEXPORT jobject JNICALL 447 JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0); 448 449 /* 450 * java.lang.reflect.Constructor 451 */ 452 JNIEXPORT jobject JNICALL 453 JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0); 454 455 /* 456 * Constant pool access; currently used to implement reflective access to annotations (JDK 1.5) 457 */ 458 459 JNIEXPORT jobject JNICALL 460 JVM_GetClassConstantPool(JNIEnv *env, jclass cls); 461 462 JNIEXPORT jint JNICALL JVM_ConstantPoolGetSize 463 (JNIEnv *env, jobject unused, jobject jcpool); 464 465 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAt 466 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 467 468 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAtIfLoaded 469 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 470 471 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAt 472 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 473 474 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAtIfLoaded 475 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 476 477 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAt 478 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 479 480 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAtIfLoaded 481 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 482 483 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetMemberRefInfoAt 484 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 485 486 JNIEXPORT jint JNICALL JVM_ConstantPoolGetIntAt 487 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 488 489 JNIEXPORT jlong JNICALL JVM_ConstantPoolGetLongAt 490 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 491 492 JNIEXPORT jfloat JNICALL JVM_ConstantPoolGetFloatAt 493 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 494 495 JNIEXPORT jdouble JNICALL JVM_ConstantPoolGetDoubleAt 496 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 497 498 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetStringAt 499 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 500 501 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetUTF8At 502 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 503 504 /* 505 * Parameter reflection 506 */ 507 508 JNIEXPORT jobjectArray JNICALL 509 JVM_GetMethodParameters(JNIEnv *env, jobject method); 510 511 /* 512 * java.security.* 513 */ 514 515 JNIEXPORT jobject JNICALL 516 JVM_DoPrivileged(JNIEnv *env, jclass cls, 517 jobject action, jobject context, jboolean wrapException); 518 519 JNIEXPORT jobject JNICALL 520 JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls); 521 522 JNIEXPORT jobject JNICALL 523 JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls); 524 525 /* 526 * Signal support, used to implement the shutdown sequence. Every VM must 527 * support JVM_SIGINT and JVM_SIGTERM, raising the former for user interrupts 528 * (^C) and the latter for external termination (kill, system shutdown, etc.). 529 * Other platform-dependent signal values may also be supported. 530 */ 531 532 JNIEXPORT void * JNICALL 533 JVM_RegisterSignal(jint sig, void *handler); 534 535 JNIEXPORT jboolean JNICALL 536 JVM_RaiseSignal(jint sig); 537 538 JNIEXPORT jint JNICALL 539 JVM_FindSignal(const char *name); 540 541 /* 542 * Retrieve the assertion directives for the specified class. 543 */ 544 JNIEXPORT jboolean JNICALL 545 JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls); 546 547 /* 548 * Retrieve the assertion directives from the VM. 549 */ 550 JNIEXPORT jobject JNICALL 551 JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused); 552 553 /* 554 * java.util.concurrent.atomic.AtomicLong 555 */ 556 JNIEXPORT jboolean JNICALL 557 JVM_SupportsCX8(void); 558 559 /* 560 * com.sun.dtrace.jsdt support 561 */ 562 563 #define JVM_TRACING_DTRACE_VERSION 1 564 565 /* 566 * Structure to pass one probe description to JVM 567 */ 568 typedef struct { 569 jmethodID method; 570 jstring function; 571 jstring name; 572 void* reserved[4]; // for future use 573 } JVM_DTraceProbe; 574 575 /** 576 * Encapsulates the stability ratings for a DTrace provider field 577 */ 578 typedef struct { 579 jint nameStability; 580 jint dataStability; 581 jint dependencyClass; 582 } JVM_DTraceInterfaceAttributes; 583 584 /* 585 * Structure to pass one provider description to JVM 586 */ 587 typedef struct { 588 jstring name; 589 JVM_DTraceProbe* probes; 590 jint probe_count; 591 JVM_DTraceInterfaceAttributes providerAttributes; 592 JVM_DTraceInterfaceAttributes moduleAttributes; 593 JVM_DTraceInterfaceAttributes functionAttributes; 594 JVM_DTraceInterfaceAttributes nameAttributes; 595 JVM_DTraceInterfaceAttributes argsAttributes; 596 void* reserved[4]; // for future use 597 } JVM_DTraceProvider; 598 599 /* 600 * Get the version number the JVM was built with 601 */ 602 JNIEXPORT jint JNICALL 603 JVM_DTraceGetVersion(JNIEnv* env); 604 605 /* 606 * Register new probe with given signature, return global handle 607 * 608 * The version passed in is the version that the library code was 609 * built with. 610 */ 611 JNIEXPORT jlong JNICALL 612 JVM_DTraceActivate(JNIEnv* env, jint version, jstring module_name, 613 jint providers_count, JVM_DTraceProvider* providers); 614 615 /* 616 * Check JSDT probe 617 */ 618 JNIEXPORT jboolean JNICALL 619 JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method); 620 621 /* 622 * Destroy custom DOF 623 */ 624 JNIEXPORT void JNICALL 625 JVM_DTraceDispose(JNIEnv* env, jlong activation_handle); 626 627 /* 628 * Check to see if DTrace is supported by OS 629 */ 630 JNIEXPORT jboolean JNICALL 631 JVM_DTraceIsSupported(JNIEnv* env); 632 633 /************************************************************************* 634 PART 2: Support for the Verifier and Class File Format Checker 635 ************************************************************************/ 636 /* 637 * Return the class name in UTF format. The result is valid 638 * until JVM_ReleaseUTf is called. 639 * 640 * The caller must treat the string as a constant and not modify it 641 * in any way. 642 */ 643 JNIEXPORT const char * JNICALL 644 JVM_GetClassNameUTF(JNIEnv *env, jclass cb); 645 646 /* 647 * Returns the constant pool types in the buffer provided by "types." 648 */ 649 JNIEXPORT void JNICALL 650 JVM_GetClassCPTypes(JNIEnv *env, jclass cb, unsigned char *types); 651 652 /* 653 * Returns the number of Constant Pool entries. 654 */ 655 JNIEXPORT jint JNICALL 656 JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cb); 657 658 /* 659 * Returns the number of *declared* fields or methods. 660 */ 661 JNIEXPORT jint JNICALL 662 JVM_GetClassFieldsCount(JNIEnv *env, jclass cb); 663 664 JNIEXPORT jint JNICALL 665 JVM_GetClassMethodsCount(JNIEnv *env, jclass cb); 666 667 /* 668 * Returns the CP indexes of exceptions raised by a given method. 669 * Places the result in the given buffer. 670 * 671 * The method is identified by method_index. 672 */ 673 JNIEXPORT void JNICALL 674 JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cb, jint method_index, 675 unsigned short *exceptions); 676 /* 677 * Returns the number of exceptions raised by a given method. 678 * The method is identified by method_index. 679 */ 680 JNIEXPORT jint JNICALL 681 JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cb, jint method_index); 682 683 /* 684 * Returns the byte code sequence of a given method. 685 * Places the result in the given buffer. 686 * 687 * The method is identified by method_index. 688 */ 689 JNIEXPORT void JNICALL 690 JVM_GetMethodIxByteCode(JNIEnv *env, jclass cb, jint method_index, 691 unsigned char *code); 692 693 /* 694 * Returns the length of the byte code sequence of a given method. 695 * The method is identified by method_index. 696 */ 697 JNIEXPORT jint JNICALL 698 JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cb, jint method_index); 699 700 /* 701 * A structure used to a capture exception table entry in a Java method. 702 */ 703 typedef struct { 704 jint start_pc; 705 jint end_pc; 706 jint handler_pc; 707 jint catchType; 708 } JVM_ExceptionTableEntryType; 709 710 /* 711 * Returns the exception table entry at entry_index of a given method. 712 * Places the result in the given buffer. 713 * 714 * The method is identified by method_index. 715 */ 716 JNIEXPORT void JNICALL 717 JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cb, jint method_index, 718 jint entry_index, 719 JVM_ExceptionTableEntryType *entry); 720 721 /* 722 * Returns the length of the exception table of a given method. 723 * The method is identified by method_index. 724 */ 725 JNIEXPORT jint JNICALL 726 JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cb, int index); 727 728 /* 729 * Returns the modifiers of a given field. 730 * The field is identified by field_index. 731 */ 732 JNIEXPORT jint JNICALL 733 JVM_GetFieldIxModifiers(JNIEnv *env, jclass cb, int index); 734 735 /* 736 * Returns the modifiers of a given method. 737 * The method is identified by method_index. 738 */ 739 JNIEXPORT jint JNICALL 740 JVM_GetMethodIxModifiers(JNIEnv *env, jclass cb, int index); 741 742 /* 743 * Returns the number of local variables of a given method. 744 * The method is identified by method_index. 745 */ 746 JNIEXPORT jint JNICALL 747 JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cb, int index); 748 749 /* 750 * Returns the number of arguments (including this pointer) of a given method. 751 * The method is identified by method_index. 752 */ 753 JNIEXPORT jint JNICALL 754 JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cb, int index); 755 756 /* 757 * Returns the maximum amount of stack (in words) used by a given method. 758 * The method is identified by method_index. 759 */ 760 JNIEXPORT jint JNICALL 761 JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cb, int index); 762 763 /* 764 * Is a given method a constructor. 765 * The method is identified by method_index. 766 */ 767 JNIEXPORT jboolean JNICALL 768 JVM_IsConstructorIx(JNIEnv *env, jclass cb, int index); 769 770 /* 771 * Is the given method generated by the VM. 772 * The method is identified by method_index. 773 */ 774 JNIEXPORT jboolean JNICALL 775 JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cb, int index); 776 777 /* 778 * Returns the name of a given method in UTF format. 779 * The result remains valid until JVM_ReleaseUTF is called. 780 * 781 * The caller must treat the string as a constant and not modify it 782 * in any way. 783 */ 784 JNIEXPORT const char * JNICALL 785 JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cb, jint index); 786 787 /* 788 * Returns the signature of a given method in UTF format. 789 * The result remains valid until JVM_ReleaseUTF is called. 790 * 791 * The caller must treat the string as a constant and not modify it 792 * in any way. 793 */ 794 JNIEXPORT const char * JNICALL 795 JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cb, jint index); 796 797 /* 798 * Returns the name of the field referred to at a given constant pool 799 * index. 800 * 801 * The result is in UTF format and remains valid until JVM_ReleaseUTF 802 * is called. 803 * 804 * The caller must treat the string as a constant and not modify it 805 * in any way. 806 */ 807 JNIEXPORT const char * JNICALL 808 JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cb, jint index); 809 810 /* 811 * Returns the name of the method referred to at a given constant pool 812 * index. 813 * 814 * The result is in UTF format and remains valid until JVM_ReleaseUTF 815 * is called. 816 * 817 * The caller must treat the string as a constant and not modify it 818 * in any way. 819 */ 820 JNIEXPORT const char * JNICALL 821 JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cb, jint index); 822 823 /* 824 * Returns the signature of the method referred to at a given constant pool 825 * index. 826 * 827 * The result is in UTF format and remains valid until JVM_ReleaseUTF 828 * is called. 829 * 830 * The caller must treat the string as a constant and not modify it 831 * in any way. 832 */ 833 JNIEXPORT const char * JNICALL 834 JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cb, jint index); 835 836 /* 837 * Returns the signature of the field referred to at a given constant pool 838 * index. 839 * 840 * The result is in UTF format and remains valid until JVM_ReleaseUTF 841 * is called. 842 * 843 * The caller must treat the string as a constant and not modify it 844 * in any way. 845 */ 846 JNIEXPORT const char * JNICALL 847 JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cb, jint index); 848 849 /* 850 * Returns the class name referred to at a given constant pool index. 851 * 852 * The result is in UTF format and remains valid until JVM_ReleaseUTF 853 * is called. 854 * 855 * The caller must treat the string as a constant and not modify it 856 * in any way. 857 */ 858 JNIEXPORT const char * JNICALL 859 JVM_GetCPClassNameUTF(JNIEnv *env, jclass cb, jint index); 860 861 /* 862 * Returns the class name referred to at a given constant pool index. 863 * 864 * The constant pool entry must refer to a CONSTANT_Fieldref. 865 * 866 * The result is in UTF format and remains valid until JVM_ReleaseUTF 867 * is called. 868 * 869 * The caller must treat the string as a constant and not modify it 870 * in any way. 871 */ 872 JNIEXPORT const char * JNICALL 873 JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cb, jint index); 874 875 /* 876 * Returns the class name referred to at a given constant pool index. 877 * 878 * The constant pool entry must refer to CONSTANT_Methodref or 879 * CONSTANT_InterfaceMethodref. 880 * 881 * The result is in UTF format and remains valid until JVM_ReleaseUTF 882 * is called. 883 * 884 * The caller must treat the string as a constant and not modify it 885 * in any way. 886 */ 887 JNIEXPORT const char * JNICALL 888 JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cb, jint index); 889 890 /* 891 * Returns the modifiers of a field in calledClass. The field is 892 * referred to in class cb at constant pool entry index. 893 * 894 * The caller must treat the string as a constant and not modify it 895 * in any way. 896 * 897 * Returns -1 if the field does not exist in calledClass. 898 */ 899 JNIEXPORT jint JNICALL 900 JVM_GetCPFieldModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass); 901 902 /* 903 * Returns the modifiers of a method in calledClass. The method is 904 * referred to in class cb at constant pool entry index. 905 * 906 * Returns -1 if the method does not exist in calledClass. 907 */ 908 JNIEXPORT jint JNICALL 909 JVM_GetCPMethodModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass); 910 911 /* 912 * Releases the UTF string obtained from the VM. 913 */ 914 JNIEXPORT void JNICALL 915 JVM_ReleaseUTF(const char *utf); 916 917 /* 918 * Compare if two classes are in the same package. 919 */ 920 JNIEXPORT jboolean JNICALL 921 JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2); 922 923 /* Get classfile constants */ 924 #include "classfile_constants.h" 925 926 /* 927 * A function defined by the byte-code verifier and called by the VM. 928 * This is not a function implemented in the VM. 929 * 930 * Returns JNI_FALSE if verification fails. A detailed error message 931 * will be places in msg_buf, whose length is specified by buf_len. 932 */ 933 typedef jboolean (*verifier_fn_t)(JNIEnv *env, 934 jclass cb, 935 char * msg_buf, 936 jint buf_len); 937 938 939 /* 940 * Support for a VM-independent class format checker. 941 */ 942 typedef struct { 943 unsigned long code; /* byte code */ 944 unsigned long excs; /* exceptions */ 945 unsigned long etab; /* catch table */ 946 unsigned long lnum; /* line number */ 947 unsigned long lvar; /* local vars */ 948 } method_size_info; 949 950 typedef struct { 951 unsigned int constants; /* constant pool */ 952 unsigned int fields; 953 unsigned int methods; 954 unsigned int interfaces; 955 unsigned int fields2; /* number of static 2-word fields */ 956 unsigned int innerclasses; /* # of records in InnerClasses attr */ 957 958 method_size_info clinit; /* memory used in clinit */ 959 method_size_info main; /* used everywhere else */ 960 } class_size_info; 961 962 /* 963 * Functions defined in libjava.so to perform string conversions. 964 * 965 */ 966 967 typedef jstring (*to_java_string_fn_t)(JNIEnv *env, char *str); 968 969 typedef char *(*to_c_string_fn_t)(JNIEnv *env, jstring s, jboolean *b); 970 971 /* This is the function defined in libjava.so that performs class 972 * format checks. This functions fills in size information about 973 * the class file and returns: 974 * 975 * 0: good 976 * -1: out of memory 977 * -2: bad format 978 * -3: unsupported version 979 * -4: bad class name 980 */ 981 982 typedef jint (*check_format_fn_t)(char *class_name, 983 unsigned char *data, 984 unsigned int data_size, 985 class_size_info *class_size, 986 char *message_buffer, 987 jint buffer_length, 988 jboolean measure_only, 989 jboolean check_relaxed); 990 991 #define JVM_RECOGNIZED_CLASS_MODIFIERS (JVM_ACC_PUBLIC | \ 992 JVM_ACC_FINAL | \ 993 JVM_ACC_SUPER | \ 994 JVM_ACC_INTERFACE | \ 995 JVM_ACC_ABSTRACT | \ 996 JVM_ACC_ANNOTATION | \ 997 JVM_ACC_ENUM | \ 998 JVM_ACC_SYNTHETIC) 999 1000 #define JVM_RECOGNIZED_FIELD_MODIFIERS (JVM_ACC_PUBLIC | \ 1001 JVM_ACC_PRIVATE | \ 1002 JVM_ACC_PROTECTED | \ 1003 JVM_ACC_STATIC | \ 1004 JVM_ACC_FINAL | \ 1005 JVM_ACC_VOLATILE | \ 1006 JVM_ACC_TRANSIENT | \ 1007 JVM_ACC_ENUM | \ 1008 JVM_ACC_SYNTHETIC) 1009 1010 #define JVM_RECOGNIZED_METHOD_MODIFIERS (JVM_ACC_PUBLIC | \ 1011 JVM_ACC_PRIVATE | \ 1012 JVM_ACC_PROTECTED | \ 1013 JVM_ACC_STATIC | \ 1014 JVM_ACC_FINAL | \ 1015 JVM_ACC_SYNCHRONIZED | \ 1016 JVM_ACC_BRIDGE | \ 1017 JVM_ACC_VARARGS | \ 1018 JVM_ACC_NATIVE | \ 1019 JVM_ACC_ABSTRACT | \ 1020 JVM_ACC_STRICT | \ 1021 JVM_ACC_SYNTHETIC) 1022 1023 /* 1024 * This is the function defined in libjava.so to perform path 1025 * canonicalization. VM call this function before opening jar files 1026 * to load system classes. 1027 * 1028 */ 1029 1030 typedef int (*canonicalize_fn_t)(JNIEnv *env, char *orig, char *out, int len); 1031 1032 /************************************************************************* 1033 PART 3: I/O and Network Support 1034 ************************************************************************/ 1035 1036 /* 1037 * Convert a pathname into native format. This function does syntactic 1038 * cleanup, such as removing redundant separator characters. It modifies 1039 * the given pathname string in place. 1040 */ 1041 JNIEXPORT char * JNICALL 1042 JVM_NativePath(char *); 1043 1044 /* 1045 * The standard printing functions supported by the Java VM. (Should they 1046 * be renamed to JVM_* in the future? 1047 */ 1048 1049 /* 1050 * BE CAREFUL! The following functions do not implement the 1051 * full feature set of standard C printf formats. 1052 */ 1053 int 1054 jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args); 1055 1056 int 1057 jio_snprintf(char *str, size_t count, const char *fmt, ...); 1058 1059 int 1060 jio_fprintf(FILE *, const char *fmt, ...); 1061 1062 int 1063 jio_vfprintf(FILE *, const char *fmt, va_list args); 1064 1065 1066 JNIEXPORT void * JNICALL 1067 JVM_RawMonitorCreate(void); 1068 1069 JNIEXPORT void JNICALL 1070 JVM_RawMonitorDestroy(void *mon); 1071 1072 JNIEXPORT jint JNICALL 1073 JVM_RawMonitorEnter(void *mon); 1074 1075 JNIEXPORT void JNICALL 1076 JVM_RawMonitorExit(void *mon); 1077 1078 /* 1079 * java.lang.management support 1080 */ 1081 JNIEXPORT void* JNICALL 1082 JVM_GetManagement(jint version); 1083 1084 /* 1085 * com.sun.tools.attach.VirtualMachine support 1086 * 1087 * Initialize the agent properties with the properties maintained in the VM. 1088 */ 1089 JNIEXPORT jobject JNICALL 1090 JVM_InitAgentProperties(JNIEnv *env, jobject agent_props); 1091 1092 JNIEXPORT jstring JNICALL 1093 JVM_GetTemporaryDirectory(JNIEnv *env); 1094 1095 /* Generics reflection support. 1096 * 1097 * Returns information about the given class's EnclosingMethod 1098 * attribute, if present, or null if the class had no enclosing 1099 * method. 1100 * 1101 * If non-null, the returned array contains three elements. Element 0 1102 * is the java.lang.Class of which the enclosing method is a member, 1103 * and elements 1 and 2 are the java.lang.Strings for the enclosing 1104 * method's name and descriptor, respectively. 1105 */ 1106 JNIEXPORT jobjectArray JNICALL 1107 JVM_GetEnclosingMethodInfo(JNIEnv* env, jclass ofClass); 1108 1109 /* ========================================================================= 1110 * The following defines a private JVM interface that the JDK can query 1111 * for the JVM version and capabilities. sun.misc.Version defines 1112 * the methods for getting the VM version and its capabilities. 1113 * 1114 * When a new bit is added, the following should be updated to provide 1115 * access to the new capability: 1116 * HS: JVM_GetVersionInfo and Abstract_VM_Version class 1117 * SDK: Version class 1118 * 1119 * Similary, a private JDK interface JDK_GetVersionInfo0 is defined for 1120 * JVM to query for the JDK version and capabilities. 1121 * 1122 * When a new bit is added, the following should be updated to provide 1123 * access to the new capability: 1124 * HS: JDK_Version class 1125 * SDK: JDK_GetVersionInfo0 1126 * 1127 * ========================================================================== 1128 */ 1129 typedef struct { 1130 /* Naming convention of RE build version string: n.n.n[_uu[c]][-<identifier>]-bxx */ 1131 unsigned int jvm_version; /* Consists of major, minor, micro (n.n.n) */ 1132 /* and build number (xx) */ 1133 unsigned int update_version : 8; /* Update release version (uu) */ 1134 unsigned int special_update_version : 8; /* Special update release version (c)*/ 1135 unsigned int reserved1 : 16; 1136 unsigned int reserved2; 1137 1138 /* The following bits represents JVM supports that JDK has dependency on. 1139 * JDK can use these bits to determine which JVM version 1140 * and support it has to maintain runtime compatibility. 1141 * 1142 * When a new bit is added in a minor or update release, make sure 1143 * the new bit is also added in the main/baseline. 1144 */ 1145 unsigned int is_attach_supported : 1; 1146 unsigned int : 31; 1147 unsigned int : 32; 1148 unsigned int : 32; 1149 } jvm_version_info; 1150 1151 #define JVM_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) 1152 #define JVM_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) 1153 #define JVM_VERSION_MICRO(version) ((version & 0x0000FF00) >> 8) 1154 1155 /* Build number is available only for RE builds. 1156 * It will be zero for internal builds. 1157 */ 1158 #define JVM_VERSION_BUILD(version) ((version & 0x000000FF)) 1159 1160 JNIEXPORT void JNICALL 1161 JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size); 1162 1163 typedef struct { 1164 // Naming convention of RE build version string: n.n.n[_uu[c]][-<identifier>]-bxx 1165 unsigned int jdk_version; /* Consists of major, minor, micro (n.n.n) */ 1166 /* and build number (xx) */ 1167 unsigned int update_version : 8; /* Update release version (uu) */ 1168 unsigned int special_update_version : 8; /* Special update release version (c)*/ 1169 unsigned int reserved1 : 16; 1170 unsigned int reserved2; 1171 1172 /* The following bits represents new JDK supports that VM has dependency on. 1173 * VM implementation can use these bits to determine which JDK version 1174 * and support it has to maintain runtime compatibility. 1175 * 1176 * When a new bit is added in a minor or update release, make sure 1177 * the new bit is also added in the main/baseline. 1178 */ 1179 unsigned int thread_park_blocker : 1; 1180 unsigned int post_vm_init_hook_enabled : 1; 1181 unsigned int pending_list_uses_discovered_field : 1; 1182 unsigned int : 29; 1183 unsigned int : 32; 1184 unsigned int : 32; 1185 } jdk_version_info; 1186 1187 #define JDK_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) 1188 #define JDK_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) 1189 #define JDK_VERSION_MICRO(version) ((version & 0x0000FF00) >> 8) 1190 1191 /* Build number is available only for RE build (i.e. JDK_BUILD_NUMBER is set to bNN) 1192 * It will be zero for internal builds. 1193 */ 1194 #define JDK_VERSION_BUILD(version) ((version & 0x000000FF)) 1195 1196 /* 1197 * This is the function JDK_GetVersionInfo0 defined in libjava.so 1198 * that is dynamically looked up by JVM. 1199 */ 1200 typedef void (*jdk_version_info_fn_t)(jdk_version_info* info, size_t info_size); 1201 1202 /* 1203 * This structure is used by the launcher to get the default thread 1204 * stack size from the VM using JNI_GetDefaultJavaVMInitArgs() with a 1205 * version of 1.1. As it is not supported otherwise, it has been removed 1206 * from jni.h 1207 */ 1208 typedef struct JDK1_1InitArgs { 1209 jint version; 1210 1211 char **properties; 1212 jint checkSource; 1213 jint nativeStackSize; 1214 jint javaStackSize; 1215 jint minHeapSize; 1216 jint maxHeapSize; 1217 jint verifyMode; 1218 char *classpath; 1219 1220 jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args); 1221 void (JNICALL *exit)(jint code); 1222 void (JNICALL *abort)(void); 1223 1224 jint enableClassGC; 1225 jint enableVerboseGC; 1226 jint disableAsyncGC; 1227 jint verbose; 1228 jboolean debugging; 1229 jint debugPort; 1230 } JDK1_1InitArgs; 1231 1232 1233 #ifdef __cplusplus 1234 } /* extern "C" */ 1235 1236 #endif /* __cplusplus */ 1237 1238 #endif /* !_JAVASOFT_JVM_H_ */