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