1 /* 2 * Copyright (c) 1997, 2011, 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 #ifndef SHARE_VM_PRIMS_JVM_H 26 #define SHARE_VM_PRIMS_JVM_H 27 28 #include "prims/jni.h" 29 #ifdef TARGET_OS_FAMILY_linux 30 # include "jvm_linux.h" 31 #endif 32 #ifdef TARGET_OS_FAMILY_solaris 33 # include "jvm_solaris.h" 34 #endif 35 #ifdef TARGET_OS_FAMILY_windows 36 # include "jvm_windows.h" 37 #endif 38 #ifdef TARGET_OS_FAMILY_bsd 39 # include "jvm_bsd.h" 40 #endif 41 42 #ifndef _JAVASOFT_JVM_H_ 43 #define _JAVASOFT_JVM_H_ 44 45 // HotSpot integration note: 46 // 47 // This file and jvm.h used with the JDK are identical, 48 // except for the three includes removed below 49 50 // #include <sys/stat.h> 51 // #include "jni.h" 52 // #include "jvm_md.h" 53 54 55 #ifdef __cplusplus 56 extern "C" { 57 #endif 58 59 /* 60 * This file contains additional functions exported from the VM. 61 * These functions are complementary to the standard JNI support. 62 * There are three parts to this file: 63 * 64 * First, this file contains the VM-related functions needed by native 65 * libraries in the standard Java API. For example, the java.lang.Object 66 * class needs VM-level functions that wait for and notify monitors. 67 * 68 * Second, this file contains the functions and constant definitions 69 * needed by the byte code verifier and class file format checker. 70 * These functions allow the verifier and format checker to be written 71 * in a VM-independent way. 72 * 73 * Third, this file contains various I/O and nerwork operations needed 74 * by the standard Java I/O and network APIs. 75 */ 76 77 /* 78 * Bump the version number when either of the following happens: 79 * 80 * 1. There is a change in JVM_* functions. 81 * 82 * 2. There is a change in the contract between VM and Java classes. 83 * For example, if the VM relies on a new private field in Thread 84 * class. 85 */ 86 87 #define JVM_INTERFACE_VERSION 4 88 89 90 JNIEXPORT jint JNICALL 91 JVM_GetInterfaceVersion(void); 92 93 /************************************************************************* 94 PART 1: Functions for Native Libraries 95 ************************************************************************/ 96 /* 97 * java.lang.Object 98 */ 99 JNIEXPORT jint JNICALL 100 JVM_IHashCode(JNIEnv *env, jobject obj); 101 102 JNIEXPORT void JNICALL 103 JVM_MonitorWait(JNIEnv *env, jobject obj, jlong ms); 104 105 JNIEXPORT void JNICALL 106 JVM_MonitorNotify(JNIEnv *env, jobject obj); 107 108 JNIEXPORT void JNICALL 109 JVM_MonitorNotifyAll(JNIEnv *env, jobject obj); 110 111 JNIEXPORT jobject JNICALL 112 JVM_Clone(JNIEnv *env, jobject obj); 113 114 /* 115 * java.lang.String 116 */ 117 JNIEXPORT jstring JNICALL 118 JVM_InternString(JNIEnv *env, jstring str); 119 120 /* 121 * java.lang.System 122 */ 123 JNIEXPORT jlong JNICALL 124 JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored); 125 126 JNIEXPORT jlong JNICALL 127 JVM_NanoTime(JNIEnv *env, jclass ignored); 128 129 JNIEXPORT void JNICALL 130 JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, 131 jobject dst, jint dst_pos, jint length); 132 133 JNIEXPORT jobject JNICALL 134 JVM_InitProperties(JNIEnv *env, jobject p); 135 136 /* 137 * java.io.File 138 */ 139 JNIEXPORT void JNICALL 140 JVM_OnExit(void (*func)(void)); 141 142 /* 143 * java.lang.Runtime 144 */ 145 JNIEXPORT void JNICALL 146 JVM_Exit(jint code); 147 148 JNIEXPORT void JNICALL 149 JVM_Halt(jint code); 150 151 JNIEXPORT void JNICALL 152 JVM_GC(void); 153 154 /* Returns the number of real-time milliseconds that have elapsed since the 155 * least-recently-inspected heap object was last inspected by the garbage 156 * collector. 157 * 158 * For simple stop-the-world collectors this value is just the time 159 * since the most recent collection. For generational collectors it is the 160 * time since the oldest generation was most recently collected. Other 161 * collectors are free to return a pessimistic estimate of the elapsed time, or 162 * simply the time since the last full collection was performed. 163 * 164 * Note that in the presence of reference objects, a given object that is no 165 * longer strongly reachable may have to be inspected multiple times before it 166 * can be reclaimed. 167 */ 168 JNIEXPORT jlong JNICALL 169 JVM_MaxObjectInspectionAge(void); 170 171 JNIEXPORT void JNICALL 172 JVM_TraceInstructions(jboolean on); 173 174 JNIEXPORT void JNICALL 175 JVM_TraceMethodCalls(jboolean on); 176 177 JNIEXPORT jlong JNICALL 178 JVM_TotalMemory(void); 179 180 JNIEXPORT jlong JNICALL 181 JVM_FreeMemory(void); 182 183 JNIEXPORT jlong JNICALL 184 JVM_MaxMemory(void); 185 186 JNIEXPORT jint JNICALL 187 JVM_ActiveProcessorCount(void); 188 189 JNIEXPORT void * JNICALL 190 JVM_LoadLibrary(const char *name); 191 192 JNIEXPORT void JNICALL 193 JVM_UnloadLibrary(void * handle); 194 195 JNIEXPORT void * JNICALL 196 JVM_FindLibraryEntry(void *handle, const char *name); 197 198 JNIEXPORT jboolean JNICALL 199 JVM_IsSupportedJNIVersion(jint version); 200 201 /* 202 * java.lang.Float and java.lang.Double 203 */ 204 JNIEXPORT jboolean JNICALL 205 JVM_IsNaN(jdouble d); 206 207 /* 208 * java.lang.Throwable 209 */ 210 JNIEXPORT void JNICALL 211 JVM_FillInStackTrace(JNIEnv *env, jobject throwable); 212 213 JNIEXPORT void JNICALL 214 JVM_PrintStackTrace(JNIEnv *env, jobject throwable, jobject printable); 215 216 JNIEXPORT jint JNICALL 217 JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable); 218 219 JNIEXPORT jobject JNICALL 220 JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index); 221 222 /* 223 * java.lang.Compiler 224 */ 225 JNIEXPORT void JNICALL 226 JVM_InitializeCompiler (JNIEnv *env, jclass compCls); 227 228 JNIEXPORT jboolean JNICALL 229 JVM_IsSilentCompiler(JNIEnv *env, jclass compCls); 230 231 JNIEXPORT jboolean JNICALL 232 JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls); 233 234 JNIEXPORT jboolean JNICALL 235 JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname); 236 237 JNIEXPORT jobject JNICALL 238 JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg); 239 240 JNIEXPORT void JNICALL 241 JVM_EnableCompiler(JNIEnv *env, jclass compCls); 242 243 JNIEXPORT void JNICALL 244 JVM_DisableCompiler(JNIEnv *env, jclass compCls); 245 246 /* 247 * java.lang.Thread 248 */ 249 JNIEXPORT void JNICALL 250 JVM_StartThread(JNIEnv *env, jobject thread); 251 252 JNIEXPORT void JNICALL 253 JVM_StopThread(JNIEnv *env, jobject thread, jobject exception); 254 255 JNIEXPORT jboolean JNICALL 256 JVM_IsThreadAlive(JNIEnv *env, jobject thread); 257 258 JNIEXPORT void JNICALL 259 JVM_SuspendThread(JNIEnv *env, jobject thread); 260 261 JNIEXPORT void JNICALL 262 JVM_ResumeThread(JNIEnv *env, jobject thread); 263 264 JNIEXPORT void JNICALL 265 JVM_SetThreadPriority(JNIEnv *env, jobject thread, jint prio); 266 267 JNIEXPORT void JNICALL 268 JVM_Yield(JNIEnv *env, jclass threadClass); 269 270 JNIEXPORT void JNICALL 271 JVM_Sleep(JNIEnv *env, jclass threadClass, jlong millis); 272 273 JNIEXPORT jobject JNICALL 274 JVM_CurrentThread(JNIEnv *env, jclass threadClass); 275 276 JNIEXPORT jint JNICALL 277 JVM_CountStackFrames(JNIEnv *env, jobject thread); 278 279 JNIEXPORT void JNICALL 280 JVM_Interrupt(JNIEnv *env, jobject thread); 281 282 JNIEXPORT jboolean JNICALL 283 JVM_IsInterrupted(JNIEnv *env, jobject thread, jboolean clearInterrupted); 284 285 JNIEXPORT jboolean JNICALL 286 JVM_HoldsLock(JNIEnv *env, jclass threadClass, jobject obj); 287 288 JNIEXPORT void JNICALL 289 JVM_DumpAllStacks(JNIEnv *env, jclass unused); 290 291 JNIEXPORT jobjectArray JNICALL 292 JVM_GetAllThreads(JNIEnv *env, jclass dummy); 293 294 /* getStackTrace() and getAllStackTraces() method */ 295 JNIEXPORT jobjectArray JNICALL 296 JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads); 297 298 /* 299 * java.lang.SecurityManager 300 */ 301 JNIEXPORT jclass JNICALL 302 JVM_CurrentLoadedClass(JNIEnv *env); 303 304 JNIEXPORT jobject JNICALL 305 JVM_CurrentClassLoader(JNIEnv *env); 306 307 JNIEXPORT jobjectArray JNICALL 308 JVM_GetClassContext(JNIEnv *env); 309 310 JNIEXPORT jint JNICALL 311 JVM_ClassDepth(JNIEnv *env, jstring name); 312 313 JNIEXPORT jint JNICALL 314 JVM_ClassLoaderDepth(JNIEnv *env); 315 316 /* 317 * java.lang.Package 318 */ 319 JNIEXPORT jstring JNICALL 320 JVM_GetSystemPackage(JNIEnv *env, jstring name); 321 322 JNIEXPORT jobjectArray JNICALL 323 JVM_GetSystemPackages(JNIEnv *env); 324 325 /* 326 * java.io.ObjectInputStream 327 */ 328 JNIEXPORT jobject JNICALL 329 JVM_AllocateNewObject(JNIEnv *env, jobject obj, jclass currClass, 330 jclass initClass); 331 332 JNIEXPORT jobject JNICALL 333 JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, 334 jint length); 335 336 JNIEXPORT jobject JNICALL 337 JVM_LatestUserDefinedLoader(JNIEnv *env); 338 339 /* 340 * This function has been deprecated and should not be considered 341 * part of the specified JVM interface. 342 */ 343 JNIEXPORT jclass JNICALL 344 JVM_LoadClass0(JNIEnv *env, jobject obj, jclass currClass, 345 jstring currClassName); 346 347 /* 348 * java.lang.reflect.Array 349 */ 350 JNIEXPORT jint JNICALL 351 JVM_GetArrayLength(JNIEnv *env, jobject arr); 352 353 JNIEXPORT jobject JNICALL 354 JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index); 355 356 JNIEXPORT jvalue JNICALL 357 JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode); 358 359 JNIEXPORT void JNICALL 360 JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val); 361 362 JNIEXPORT void JNICALL 363 JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, 364 unsigned char vCode); 365 366 JNIEXPORT jobject JNICALL 367 JVM_NewArray(JNIEnv *env, jclass eltClass, jint length); 368 369 JNIEXPORT jobject JNICALL 370 JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim); 371 372 /* 373 * java.lang.Class and java.lang.ClassLoader 374 */ 375 /* 376 * Returns the class in which the code invoking the native method 377 * belongs. 378 * 379 * Note that in JDK 1.1, native methods did not create a frame. 380 * In 1.2, they do. Therefore native methods like Class.forName 381 * can no longer look at the current frame for the caller class. 382 */ 383 JNIEXPORT jclass JNICALL 384 JVM_GetCallerClass(JNIEnv *env, int n); 385 386 /* 387 * Find primitive classes 388 * utf: class name 389 */ 390 JNIEXPORT jclass JNICALL 391 JVM_FindPrimitiveClass(JNIEnv *env, const char *utf); 392 393 /* 394 * Link the class 395 */ 396 JNIEXPORT void JNICALL 397 JVM_ResolveClass(JNIEnv *env, jclass cls); 398 399 /* 400 * Find a class from a given class loader. Throw ClassNotFoundException 401 * or NoClassDefFoundError depending on the value of the last 402 * argument. 403 */ 404 JNIEXPORT jclass JNICALL 405 JVM_FindClassFromClassLoader(JNIEnv *env, const char *name, jboolean init, 406 jobject loader, jboolean throwError); 407 408 /* 409 * Find a class from a boot class loader. Returns NULL if class not found. 410 */ 411 JNIEXPORT jclass JNICALL 412 JVM_FindClassFromBootLoader(JNIEnv *env, const char *name); 413 414 /* 415 * Find a class from a given class. 416 */ 417 JNIEXPORT jclass JNICALL 418 JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, 419 jclass from); 420 421 /* Find a loaded class cached by the VM */ 422 JNIEXPORT jclass JNICALL 423 JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name); 424 425 /* Define a class */ 426 JNIEXPORT jclass JNICALL 427 JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, 428 jsize len, jobject pd); 429 430 /* Define a class with a source (added in JDK1.5) */ 431 JNIEXPORT jclass JNICALL 432 JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, 433 const jbyte *buf, jsize len, jobject pd, 434 const char *source); 435 436 /* Define a class with a source with conditional verification (added HSX 14) 437 * -Xverify:all will verify anyway, -Xverify:none will not verify, 438 * -Xverify:remote (default) will obey this conditional 439 * i.e. true = should_verify_class 440 */ 441 JNIEXPORT jclass JNICALL 442 JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name, 443 jobject loader, const jbyte *buf, 444 jsize len, jobject pd, const char *source, 445 jboolean verify); 446 447 /* 448 * Reflection support functions 449 */ 450 451 JNIEXPORT jstring JNICALL 452 JVM_GetClassName(JNIEnv *env, jclass cls); 453 454 JNIEXPORT jobjectArray JNICALL 455 JVM_GetClassInterfaces(JNIEnv *env, jclass cls); 456 457 JNIEXPORT jobject JNICALL 458 JVM_GetClassLoader(JNIEnv *env, jclass cls); 459 460 JNIEXPORT jboolean JNICALL 461 JVM_IsInterface(JNIEnv *env, jclass cls); 462 463 JNIEXPORT jobjectArray JNICALL 464 JVM_GetClassSigners(JNIEnv *env, jclass cls); 465 466 JNIEXPORT void JNICALL 467 JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers); 468 469 JNIEXPORT jobject JNICALL 470 JVM_GetProtectionDomain(JNIEnv *env, jclass cls); 471 472 JNIEXPORT void JNICALL 473 JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain); 474 475 JNIEXPORT jboolean JNICALL 476 JVM_IsArrayClass(JNIEnv *env, jclass cls); 477 478 JNIEXPORT jboolean JNICALL 479 JVM_IsPrimitiveClass(JNIEnv *env, jclass cls); 480 481 JNIEXPORT jclass JNICALL 482 JVM_GetComponentType(JNIEnv *env, jclass cls); 483 484 JNIEXPORT jint JNICALL 485 JVM_GetClassModifiers(JNIEnv *env, jclass cls); 486 487 JNIEXPORT jobjectArray JNICALL 488 JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass); 489 490 JNIEXPORT jclass JNICALL 491 JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass); 492 493 /* Generics support (JDK 1.5) */ 494 JNIEXPORT jstring JNICALL 495 JVM_GetClassSignature(JNIEnv *env, jclass cls); 496 497 /* Annotations support (JDK 1.5) */ 498 JNIEXPORT jbyteArray JNICALL 499 JVM_GetClassAnnotations(JNIEnv *env, jclass cls); 500 501 /* Annotations support (JDK 1.6) */ 502 503 // field is a handle to a java.lang.reflect.Field object 504 JNIEXPORT jbyteArray JNICALL 505 JVM_GetFieldAnnotations(JNIEnv *env, jobject field); 506 507 // method is a handle to a java.lang.reflect.Method object 508 JNIEXPORT jbyteArray JNICALL 509 JVM_GetMethodAnnotations(JNIEnv *env, jobject method); 510 511 // method is a handle to a java.lang.reflect.Method object 512 JNIEXPORT jbyteArray JNICALL 513 JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method); 514 515 // method is a handle to a java.lang.reflect.Method object 516 JNIEXPORT jbyteArray JNICALL 517 JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method); 518 519 520 /* 521 * New (JDK 1.4) reflection implementation 522 */ 523 524 JNIEXPORT jobjectArray JNICALL 525 JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly); 526 527 JNIEXPORT jobjectArray JNICALL 528 JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly); 529 530 JNIEXPORT jobjectArray JNICALL 531 JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly); 532 533 /* Differs from JVM_GetClassModifiers in treatment of inner classes. 534 This returns the access flags for the class as specified in the 535 class file rather than searching the InnerClasses attribute (if 536 present) to find the source-level access flags. Only the values of 537 the low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be 538 valid. */ 539 JNIEXPORT jint JNICALL 540 JVM_GetClassAccessFlags(JNIEnv *env, jclass cls); 541 542 /* 543 * Constant pool access; currently used to implement reflective access to annotations (JDK 1.5) 544 */ 545 546 JNIEXPORT jobject JNICALL 547 JVM_GetClassConstantPool(JNIEnv *env, jclass cls); 548 549 JNIEXPORT jint JNICALL JVM_ConstantPoolGetSize 550 (JNIEnv *env, jobject unused, jobject jcpool); 551 552 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAt 553 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 554 555 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAtIfLoaded 556 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 557 558 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAt 559 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 560 561 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAtIfLoaded 562 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 563 564 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAt 565 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 566 567 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAtIfLoaded 568 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 569 570 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetMemberRefInfoAt 571 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 572 573 JNIEXPORT jint JNICALL JVM_ConstantPoolGetIntAt 574 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 575 576 JNIEXPORT jlong JNICALL JVM_ConstantPoolGetLongAt 577 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 578 579 JNIEXPORT jfloat JNICALL JVM_ConstantPoolGetFloatAt 580 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 581 582 JNIEXPORT jdouble JNICALL JVM_ConstantPoolGetDoubleAt 583 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 584 585 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetStringAt 586 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 587 588 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetUTF8At 589 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 590 591 /* 592 * java.security.* 593 */ 594 595 JNIEXPORT jobject JNICALL 596 JVM_DoPrivileged(JNIEnv *env, jclass cls, 597 jobject action, jobject context, jboolean wrapException); 598 599 JNIEXPORT jobject JNICALL 600 JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls); 601 602 JNIEXPORT jobject JNICALL 603 JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls); 604 605 /* 606 * Signal support, used to implement the shutdown sequence. Every VM must 607 * support JVM_SIGINT and JVM_SIGTERM, raising the former for user interrupts 608 * (^C) and the latter for external termination (kill, system shutdown, etc.). 609 * Other platform-dependent signal values may also be supported. 610 */ 611 612 JNIEXPORT void * JNICALL 613 JVM_RegisterSignal(jint sig, void *handler); 614 615 JNIEXPORT jboolean JNICALL 616 JVM_RaiseSignal(jint sig); 617 618 JNIEXPORT jint JNICALL 619 JVM_FindSignal(const char *name); 620 621 /* 622 * Retrieve the assertion directives for the specified class. 623 */ 624 JNIEXPORT jboolean JNICALL 625 JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls); 626 627 /* 628 * Retrieve the assertion directives from the VM. 629 */ 630 JNIEXPORT jobject JNICALL 631 JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused); 632 633 /* 634 * sun.misc.AtomicLong 635 */ 636 JNIEXPORT jboolean JNICALL 637 JVM_SupportsCX8(void); 638 639 JNIEXPORT jboolean JNICALL 640 JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fldID, jlong oldVal, jlong newVal); 641 642 /* 643 * com.sun.dtrace.jsdt support 644 */ 645 646 #define JVM_TRACING_DTRACE_VERSION 1 647 648 /* 649 * Structure to pass one probe description to JVM. 650 * 651 * The VM will overwrite the definition of the referenced method with 652 * code that will fire the probe. 653 */ 654 typedef struct { 655 jmethodID method; 656 jstring function; 657 jstring name; 658 void* reserved[4]; // for future use 659 } JVM_DTraceProbe; 660 661 /** 662 * Encapsulates the stability ratings for a DTrace provider field 663 */ 664 typedef struct { 665 jint nameStability; 666 jint dataStability; 667 jint dependencyClass; 668 } JVM_DTraceInterfaceAttributes; 669 670 /* 671 * Structure to pass one provider description to JVM 672 */ 673 typedef struct { 674 jstring name; 675 JVM_DTraceProbe* probes; 676 jint probe_count; 677 JVM_DTraceInterfaceAttributes providerAttributes; 678 JVM_DTraceInterfaceAttributes moduleAttributes; 679 JVM_DTraceInterfaceAttributes functionAttributes; 680 JVM_DTraceInterfaceAttributes nameAttributes; 681 JVM_DTraceInterfaceAttributes argsAttributes; 682 void* reserved[4]; // for future use 683 } JVM_DTraceProvider; 684 685 /* 686 * Get the version number the JVM was built with 687 */ 688 JNIEXPORT jint JNICALL 689 JVM_DTraceGetVersion(JNIEnv* env); 690 691 /* 692 * Register new probe with given signature, return global handle 693 * 694 * The version passed in is the version that the library code was 695 * built with. 696 */ 697 JNIEXPORT jlong JNICALL 698 JVM_DTraceActivate(JNIEnv* env, jint version, jstring module_name, 699 jint providers_count, JVM_DTraceProvider* providers); 700 701 /* 702 * Check JSDT probe 703 */ 704 JNIEXPORT jboolean JNICALL 705 JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method); 706 707 /* 708 * Destroy custom DOF 709 */ 710 JNIEXPORT void JNICALL 711 JVM_DTraceDispose(JNIEnv* env, jlong handle); 712 713 /* 714 * Check to see if DTrace is supported by OS 715 */ 716 JNIEXPORT jboolean JNICALL 717 JVM_DTraceIsSupported(JNIEnv* env); 718 719 /************************************************************************* 720 PART 2: Support for the Verifier and Class File Format Checker 721 ************************************************************************/ 722 /* 723 * Return the class name in UTF format. The result is valid 724 * until JVM_ReleaseUTf is called. 725 * 726 * The caller must treat the string as a constant and not modify it 727 * in any way. 728 */ 729 JNIEXPORT const char * JNICALL 730 JVM_GetClassNameUTF(JNIEnv *env, jclass cb); 731 732 /* 733 * Returns the constant pool types in the buffer provided by "types." 734 */ 735 JNIEXPORT void JNICALL 736 JVM_GetClassCPTypes(JNIEnv *env, jclass cb, unsigned char *types); 737 738 /* 739 * Returns the number of Constant Pool entries. 740 */ 741 JNIEXPORT jint JNICALL 742 JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cb); 743 744 /* 745 * Returns the number of *declared* fields or methods. 746 */ 747 JNIEXPORT jint JNICALL 748 JVM_GetClassFieldsCount(JNIEnv *env, jclass cb); 749 750 JNIEXPORT jint JNICALL 751 JVM_GetClassMethodsCount(JNIEnv *env, jclass cb); 752 753 /* 754 * Returns the CP indexes of exceptions raised by a given method. 755 * Places the result in the given buffer. 756 * 757 * The method is identified by method_index. 758 */ 759 JNIEXPORT void JNICALL 760 JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cb, jint method_index, 761 unsigned short *exceptions); 762 /* 763 * Returns the number of exceptions raised by a given method. 764 * The method is identified by method_index. 765 */ 766 JNIEXPORT jint JNICALL 767 JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cb, jint method_index); 768 769 /* 770 * Returns the byte code sequence of a given method. 771 * Places the result in the given buffer. 772 * 773 * The method is identified by method_index. 774 */ 775 JNIEXPORT void JNICALL 776 JVM_GetMethodIxByteCode(JNIEnv *env, jclass cb, jint method_index, 777 unsigned char *code); 778 779 /* 780 * Returns the length of the byte code sequence of a given method. 781 * The method is identified by method_index. 782 */ 783 JNIEXPORT jint JNICALL 784 JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cb, jint method_index); 785 786 /* 787 * A structure used to a capture exception table entry in a Java method. 788 */ 789 typedef struct { 790 jint start_pc; 791 jint end_pc; 792 jint handler_pc; 793 jint catchType; 794 } JVM_ExceptionTableEntryType; 795 796 /* 797 * Returns the exception table entry at entry_index of a given method. 798 * Places the result in the given buffer. 799 * 800 * The method is identified by method_index. 801 */ 802 JNIEXPORT void JNICALL 803 JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cb, jint method_index, 804 jint entry_index, 805 JVM_ExceptionTableEntryType *entry); 806 807 /* 808 * Returns the length of the exception table of a given method. 809 * The method is identified by method_index. 810 */ 811 JNIEXPORT jint JNICALL 812 JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cb, int index); 813 814 /* 815 * Returns the modifiers of a given field. 816 * The field is identified by field_index. 817 */ 818 JNIEXPORT jint JNICALL 819 JVM_GetFieldIxModifiers(JNIEnv *env, jclass cb, int index); 820 821 /* 822 * Returns the modifiers of a given method. 823 * The method is identified by method_index. 824 */ 825 JNIEXPORT jint JNICALL 826 JVM_GetMethodIxModifiers(JNIEnv *env, jclass cb, int index); 827 828 /* 829 * Returns the number of local variables of a given method. 830 * The method is identified by method_index. 831 */ 832 JNIEXPORT jint JNICALL 833 JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cb, int index); 834 835 /* 836 * Returns the number of arguments (including this pointer) of a given method. 837 * The method is identified by method_index. 838 */ 839 JNIEXPORT jint JNICALL 840 JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cb, int index); 841 842 /* 843 * Returns the maximum amount of stack (in words) used by a given method. 844 * The method is identified by method_index. 845 */ 846 JNIEXPORT jint JNICALL 847 JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cb, int index); 848 849 /* 850 * Is a given method a constructor. 851 * The method is identified by method_index. 852 */ 853 JNIEXPORT jboolean JNICALL 854 JVM_IsConstructorIx(JNIEnv *env, jclass cb, int index); 855 856 /* 857 * Returns the name of a given method in UTF format. 858 * The result remains valid until JVM_ReleaseUTF is called. 859 * 860 * The caller must treat the string as a constant and not modify it 861 * in any way. 862 */ 863 JNIEXPORT const char * JNICALL 864 JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cb, jint index); 865 866 /* 867 * Returns the signature of a given method in UTF format. 868 * The result remains valid until JVM_ReleaseUTF is called. 869 * 870 * The caller must treat the string as a constant and not modify it 871 * in any way. 872 */ 873 JNIEXPORT const char * JNICALL 874 JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cb, jint index); 875 876 /* 877 * Returns the name of the field refered to at a given constant pool 878 * index. 879 * 880 * The result is in UTF format and remains valid until JVM_ReleaseUTF 881 * is called. 882 * 883 * The caller must treat the string as a constant and not modify it 884 * in any way. 885 */ 886 JNIEXPORT const char * JNICALL 887 JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cb, jint index); 888 889 /* 890 * Returns the name of the method refered to at a given constant pool 891 * index. 892 * 893 * The result is in UTF format and remains valid until JVM_ReleaseUTF 894 * is called. 895 * 896 * The caller must treat the string as a constant and not modify it 897 * in any way. 898 */ 899 JNIEXPORT const char * JNICALL 900 JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cb, jint index); 901 902 /* 903 * Returns the signature of the method refered to at a given constant pool 904 * index. 905 * 906 * The result is in UTF format and remains valid until JVM_ReleaseUTF 907 * is called. 908 * 909 * The caller must treat the string as a constant and not modify it 910 * in any way. 911 */ 912 JNIEXPORT const char * JNICALL 913 JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cb, jint index); 914 915 /* 916 * Returns the signature of the field refered to at a given constant pool 917 * index. 918 * 919 * The result is in UTF format and remains valid until JVM_ReleaseUTF 920 * is called. 921 * 922 * The caller must treat the string as a constant and not modify it 923 * in any way. 924 */ 925 JNIEXPORT const char * JNICALL 926 JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cb, jint index); 927 928 /* 929 * Returns the class name refered to at a given constant pool index. 930 * 931 * The result is in UTF format and remains valid until JVM_ReleaseUTF 932 * is called. 933 * 934 * The caller must treat the string as a constant and not modify it 935 * in any way. 936 */ 937 JNIEXPORT const char * JNICALL 938 JVM_GetCPClassNameUTF(JNIEnv *env, jclass cb, jint index); 939 940 /* 941 * Returns the class name refered to at a given constant pool index. 942 * 943 * The constant pool entry must refer to a CONSTANT_Fieldref. 944 * 945 * The result is in UTF format and remains valid until JVM_ReleaseUTF 946 * is called. 947 * 948 * The caller must treat the string as a constant and not modify it 949 * in any way. 950 */ 951 JNIEXPORT const char * JNICALL 952 JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cb, jint index); 953 954 /* 955 * Returns the class name refered to at a given constant pool index. 956 * 957 * The constant pool entry must refer to CONSTANT_Methodref or 958 * CONSTANT_InterfaceMethodref. 959 * 960 * The result is in UTF format and remains valid until JVM_ReleaseUTF 961 * is called. 962 * 963 * The caller must treat the string as a constant and not modify it 964 * in any way. 965 */ 966 JNIEXPORT const char * JNICALL 967 JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cb, jint index); 968 969 /* 970 * Returns the modifiers of a field in calledClass. The field is 971 * referred to in class cb at constant pool entry index. 972 * 973 * The caller must treat the string as a constant and not modify it 974 * in any way. 975 * 976 * Returns -1 if the field does not exist in calledClass. 977 */ 978 JNIEXPORT jint JNICALL 979 JVM_GetCPFieldModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass); 980 981 /* 982 * Returns the modifiers of a method in calledClass. The method is 983 * referred to in class cb at constant pool entry index. 984 * 985 * Returns -1 if the method does not exist in calledClass. 986 */ 987 JNIEXPORT jint JNICALL 988 JVM_GetCPMethodModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass); 989 990 /* 991 * Releases the UTF string obtained from the VM. 992 */ 993 JNIEXPORT void JNICALL 994 JVM_ReleaseUTF(const char *utf); 995 996 /* 997 * Compare if two classes are in the same package. 998 */ 999 JNIEXPORT jboolean JNICALL 1000 JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2); 1001 1002 /* Constants in class files */ 1003 1004 #define JVM_ACC_PUBLIC 0x0001 /* visible to everyone */ 1005 #define JVM_ACC_PRIVATE 0x0002 /* visible only to the defining class */ 1006 #define JVM_ACC_PROTECTED 0x0004 /* visible to subclasses */ 1007 #define JVM_ACC_STATIC 0x0008 /* instance variable is static */ 1008 #define JVM_ACC_FINAL 0x0010 /* no further subclassing, overriding */ 1009 #define JVM_ACC_SYNCHRONIZED 0x0020 /* wrap method call in monitor lock */ 1010 #define JVM_ACC_SUPER 0x0020 /* funky handling of invokespecial */ 1011 #define JVM_ACC_VOLATILE 0x0040 /* can not cache in registers */ 1012 #define JVM_ACC_BRIDGE 0x0040 /* bridge method generated by compiler */ 1013 #define JVM_ACC_TRANSIENT 0x0080 /* not persistent */ 1014 #define JVM_ACC_VARARGS 0x0080 /* method declared with variable number of args */ 1015 #define JVM_ACC_NATIVE 0x0100 /* implemented in C */ 1016 #define JVM_ACC_INTERFACE 0x0200 /* class is an interface */ 1017 #define JVM_ACC_ABSTRACT 0x0400 /* no definition provided */ 1018 #define JVM_ACC_STRICT 0x0800 /* strict floating point */ 1019 #define JVM_ACC_SYNTHETIC 0x1000 /* compiler-generated class, method or field */ 1020 #define JVM_ACC_ANNOTATION 0x2000 /* annotation type */ 1021 #define JVM_ACC_ENUM 0x4000 /* field is declared as element of enum */ 1022 1023 #define JVM_ACC_PUBLIC_BIT 0 1024 #define JVM_ACC_PRIVATE_BIT 1 1025 #define JVM_ACC_PROTECTED_BIT 2 1026 #define JVM_ACC_STATIC_BIT 3 1027 #define JVM_ACC_FINAL_BIT 4 1028 #define JVM_ACC_SYNCHRONIZED_BIT 5 1029 #define JVM_ACC_SUPER_BIT 5 1030 #define JVM_ACC_VOLATILE_BIT 6 1031 #define JVM_ACC_BRIDGE_BIT 6 1032 #define JVM_ACC_TRANSIENT_BIT 7 1033 #define JVM_ACC_VARARGS_BIT 7 1034 #define JVM_ACC_NATIVE_BIT 8 1035 #define JVM_ACC_INTERFACE_BIT 9 1036 #define JVM_ACC_ABSTRACT_BIT 10 1037 #define JVM_ACC_STRICT_BIT 11 1038 #define JVM_ACC_SYNTHETIC_BIT 12 1039 #define JVM_ACC_ANNOTATION_BIT 13 1040 #define JVM_ACC_ENUM_BIT 14 1041 1042 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/utilities/ConstantTag.java 1043 enum { 1044 JVM_CONSTANT_Utf8 = 1, 1045 JVM_CONSTANT_Unicode, /* unused */ 1046 JVM_CONSTANT_Integer, 1047 JVM_CONSTANT_Float, 1048 JVM_CONSTANT_Long, 1049 JVM_CONSTANT_Double, 1050 JVM_CONSTANT_Class, 1051 JVM_CONSTANT_String, 1052 JVM_CONSTANT_Fieldref, 1053 JVM_CONSTANT_Methodref, 1054 JVM_CONSTANT_InterfaceMethodref, 1055 JVM_CONSTANT_NameAndType, 1056 JVM_CONSTANT_MethodHandle = 15, // JSR 292 1057 JVM_CONSTANT_MethodType = 16, // JSR 292 1058 //JVM_CONSTANT_(unused) = 17, // JSR 292 early drafts only 1059 JVM_CONSTANT_InvokeDynamic = 18, // JSR 292 1060 JVM_CONSTANT_ExternalMax = 18 // Last tag found in classfiles 1061 }; 1062 1063 /* JVM_CONSTANT_MethodHandle subtypes */ 1064 enum { 1065 JVM_REF_getField = 1, 1066 JVM_REF_getStatic = 2, 1067 JVM_REF_putField = 3, 1068 JVM_REF_putStatic = 4, 1069 JVM_REF_invokeVirtual = 5, 1070 JVM_REF_invokeStatic = 6, 1071 JVM_REF_invokeSpecial = 7, 1072 JVM_REF_newInvokeSpecial = 8, 1073 JVM_REF_invokeInterface = 9 1074 }; 1075 1076 /* Used in the newarray instruction. */ 1077 1078 #define JVM_T_BOOLEAN 4 1079 #define JVM_T_CHAR 5 1080 #define JVM_T_FLOAT 6 1081 #define JVM_T_DOUBLE 7 1082 #define JVM_T_BYTE 8 1083 #define JVM_T_SHORT 9 1084 #define JVM_T_INT 10 1085 #define JVM_T_LONG 11 1086 1087 /* JVM method signatures */ 1088 1089 #define JVM_SIGNATURE_ARRAY '[' 1090 #define JVM_SIGNATURE_BYTE 'B' 1091 #define JVM_SIGNATURE_CHAR 'C' 1092 #define JVM_SIGNATURE_CLASS 'L' 1093 #define JVM_SIGNATURE_ENDCLASS ';' 1094 #define JVM_SIGNATURE_ENUM 'E' 1095 #define JVM_SIGNATURE_FLOAT 'F' 1096 #define JVM_SIGNATURE_DOUBLE 'D' 1097 #define JVM_SIGNATURE_FUNC '(' 1098 #define JVM_SIGNATURE_ENDFUNC ')' 1099 #define JVM_SIGNATURE_INT 'I' 1100 #define JVM_SIGNATURE_LONG 'J' 1101 #define JVM_SIGNATURE_SHORT 'S' 1102 #define JVM_SIGNATURE_VOID 'V' 1103 #define JVM_SIGNATURE_BOOLEAN 'Z' 1104 1105 /* 1106 * A function defined by the byte-code verifier and called by the VM. 1107 * This is not a function implemented in the VM. 1108 * 1109 * Returns JNI_FALSE if verification fails. A detailed error message 1110 * will be places in msg_buf, whose length is specified by buf_len. 1111 */ 1112 typedef jboolean (*verifier_fn_t)(JNIEnv *env, 1113 jclass cb, 1114 char * msg_buf, 1115 jint buf_len); 1116 1117 1118 /* 1119 * Support for a VM-independent class format checker. 1120 */ 1121 typedef struct { 1122 unsigned long code; /* byte code */ 1123 unsigned long excs; /* exceptions */ 1124 unsigned long etab; /* catch table */ 1125 unsigned long lnum; /* line number */ 1126 unsigned long lvar; /* local vars */ 1127 } method_size_info; 1128 1129 typedef struct { 1130 unsigned int constants; /* constant pool */ 1131 unsigned int fields; 1132 unsigned int methods; 1133 unsigned int interfaces; 1134 unsigned int fields2; /* number of static 2-word fields */ 1135 unsigned int innerclasses; /* # of records in InnerClasses attr */ 1136 1137 method_size_info clinit; /* memory used in clinit */ 1138 method_size_info main; /* used everywhere else */ 1139 } class_size_info; 1140 1141 /* 1142 * Functions defined in libjava.so to perform string conversions. 1143 * 1144 */ 1145 1146 typedef jstring (*to_java_string_fn_t)(JNIEnv *env, char *str); 1147 1148 typedef char *(*to_c_string_fn_t)(JNIEnv *env, jstring s, jboolean *b); 1149 1150 /* This is the function defined in libjava.so that performs class 1151 * format checks. This functions fills in size information about 1152 * the class file and returns: 1153 * 1154 * 0: good 1155 * -1: out of memory 1156 * -2: bad format 1157 * -3: unsupported version 1158 * -4: bad class name 1159 */ 1160 1161 typedef jint (*check_format_fn_t)(char *class_name, 1162 unsigned char *data, 1163 unsigned int data_size, 1164 class_size_info *class_size, 1165 char *message_buffer, 1166 jint buffer_length, 1167 jboolean measure_only, 1168 jboolean check_relaxed); 1169 1170 #define JVM_RECOGNIZED_CLASS_MODIFIERS (JVM_ACC_PUBLIC | \ 1171 JVM_ACC_FINAL | \ 1172 JVM_ACC_SUPER | \ 1173 JVM_ACC_INTERFACE | \ 1174 JVM_ACC_ABSTRACT | \ 1175 JVM_ACC_ANNOTATION | \ 1176 JVM_ACC_ENUM | \ 1177 JVM_ACC_SYNTHETIC) 1178 1179 #define JVM_RECOGNIZED_FIELD_MODIFIERS (JVM_ACC_PUBLIC | \ 1180 JVM_ACC_PRIVATE | \ 1181 JVM_ACC_PROTECTED | \ 1182 JVM_ACC_STATIC | \ 1183 JVM_ACC_FINAL | \ 1184 JVM_ACC_VOLATILE | \ 1185 JVM_ACC_TRANSIENT | \ 1186 JVM_ACC_ENUM | \ 1187 JVM_ACC_SYNTHETIC) 1188 1189 #define JVM_RECOGNIZED_METHOD_MODIFIERS (JVM_ACC_PUBLIC | \ 1190 JVM_ACC_PRIVATE | \ 1191 JVM_ACC_PROTECTED | \ 1192 JVM_ACC_STATIC | \ 1193 JVM_ACC_FINAL | \ 1194 JVM_ACC_SYNCHRONIZED | \ 1195 JVM_ACC_BRIDGE | \ 1196 JVM_ACC_VARARGS | \ 1197 JVM_ACC_NATIVE | \ 1198 JVM_ACC_ABSTRACT | \ 1199 JVM_ACC_STRICT | \ 1200 JVM_ACC_SYNTHETIC) 1201 1202 /* 1203 * This is the function defined in libjava.so to perform path 1204 * canonicalization. VM call this function before opening jar files 1205 * to load system classes. 1206 * 1207 */ 1208 1209 typedef int (*canonicalize_fn_t)(JNIEnv *env, char *orig, char *out, int len); 1210 1211 /************************************************************************* 1212 PART 3: I/O and Network Support 1213 ************************************************************************/ 1214 1215 /* Note that the JVM IO functions are expected to return JVM_IO_ERR 1216 * when there is any kind of error. The caller can then use the 1217 * platform specific support (e.g., errno) to get the detailed 1218 * error info. The JVM_GetLastErrorString procedure may also be used 1219 * to obtain a descriptive error string. 1220 */ 1221 #define JVM_IO_ERR (-1) 1222 1223 /* For interruptible IO. Returning JVM_IO_INTR indicates that an IO 1224 * operation has been disrupted by Thread.interrupt. There are a 1225 * number of technical difficulties related to interruptible IO that 1226 * need to be solved. For example, most existing programs do not handle 1227 * InterruptedIOExceptions specially, they simply treat those as any 1228 * IOExceptions, which typically indicate fatal errors. 1229 * 1230 * There are also two modes of operation for interruptible IO. In the 1231 * resumption mode, an interrupted IO operation is guaranteed not to 1232 * have any side-effects, and can be restarted. In the termination mode, 1233 * an interrupted IO operation corrupts the underlying IO stream, so 1234 * that the only reasonable operation on an interrupted stream is to 1235 * close that stream. The resumption mode seems to be impossible to 1236 * implement on Win32 and Solaris. Implementing the termination mode is 1237 * easier, but it's not clear that's the right semantics. 1238 * 1239 * Interruptible IO is not supported on Win32.It can be enabled/disabled 1240 * using a compile-time flag on Solaris. Third-party JVM ports do not 1241 * need to implement interruptible IO. 1242 */ 1243 #define JVM_IO_INTR (-2) 1244 1245 /* Write a string into the given buffer, in the platform's local encoding, 1246 * that describes the most recent system-level error to occur in this thread. 1247 * Return the length of the string or zero if no error occurred. 1248 */ 1249 JNIEXPORT jint JNICALL 1250 JVM_GetLastErrorString(char *buf, int len); 1251 1252 /* 1253 * Convert a pathname into native format. This function does syntactic 1254 * cleanup, such as removing redundant separator characters. It modifies 1255 * the given pathname string in place. 1256 */ 1257 JNIEXPORT char * JNICALL 1258 JVM_NativePath(char *); 1259 1260 /* 1261 * JVM I/O error codes 1262 */ 1263 #define JVM_EEXIST -100 1264 1265 /* 1266 * Open a file descriptor. This function returns a negative error code 1267 * on error, and a non-negative integer that is the file descriptor on 1268 * success. 1269 */ 1270 JNIEXPORT jint JNICALL 1271 JVM_Open(const char *fname, jint flags, jint mode); 1272 1273 /* 1274 * Close a file descriptor. This function returns -1 on error, and 0 1275 * on success. 1276 * 1277 * fd the file descriptor to close. 1278 */ 1279 JNIEXPORT jint JNICALL 1280 JVM_Close(jint fd); 1281 1282 /* 1283 * Read data from a file decriptor into a char array. 1284 * 1285 * fd the file descriptor to read from. 1286 * buf the buffer where to put the read data. 1287 * nbytes the number of bytes to read. 1288 * 1289 * This function returns -1 on error, and 0 on success. 1290 */ 1291 JNIEXPORT jint JNICALL 1292 JVM_Read(jint fd, char *buf, jint nbytes); 1293 1294 /* 1295 * Write data from a char array to a file decriptor. 1296 * 1297 * fd the file descriptor to read from. 1298 * buf the buffer from which to fetch the data. 1299 * nbytes the number of bytes to write. 1300 * 1301 * This function returns -1 on error, and 0 on success. 1302 */ 1303 JNIEXPORT jint JNICALL 1304 JVM_Write(jint fd, char *buf, jint nbytes); 1305 1306 /* 1307 * Returns the number of bytes available for reading from a given file 1308 * descriptor 1309 */ 1310 JNIEXPORT jint JNICALL 1311 JVM_Available(jint fd, jlong *pbytes); 1312 1313 /* 1314 * Move the file descriptor pointer from whence by offset. 1315 * 1316 * fd the file descriptor to move. 1317 * offset the number of bytes to move it by. 1318 * whence the start from where to move it. 1319 * 1320 * This function returns the resulting pointer location. 1321 */ 1322 JNIEXPORT jlong JNICALL 1323 JVM_Lseek(jint fd, jlong offset, jint whence); 1324 1325 /* 1326 * Set the length of the file associated with the given descriptor to the given 1327 * length. If the new length is longer than the current length then the file 1328 * is extended; the contents of the extended portion are not defined. The 1329 * value of the file pointer is undefined after this procedure returns. 1330 */ 1331 JNIEXPORT jint JNICALL 1332 JVM_SetLength(jint fd, jlong length); 1333 1334 /* 1335 * Synchronize the file descriptor's in memory state with that of the 1336 * physical device. Return of -1 is an error, 0 is OK. 1337 */ 1338 JNIEXPORT jint JNICALL 1339 JVM_Sync(jint fd); 1340 1341 /* 1342 * Networking library support 1343 */ 1344 1345 JNIEXPORT jint JNICALL 1346 JVM_InitializeSocketLibrary(void); 1347 1348 struct sockaddr; 1349 1350 JNIEXPORT jint JNICALL 1351 JVM_Socket(jint domain, jint type, jint protocol); 1352 1353 JNIEXPORT jint JNICALL 1354 JVM_SocketClose(jint fd); 1355 1356 JNIEXPORT jint JNICALL 1357 JVM_SocketShutdown(jint fd, jint howto); 1358 1359 JNIEXPORT jint JNICALL 1360 JVM_Recv(jint fd, char *buf, jint nBytes, jint flags); 1361 1362 JNIEXPORT jint JNICALL 1363 JVM_Send(jint fd, char *buf, jint nBytes, jint flags); 1364 1365 JNIEXPORT jint JNICALL 1366 JVM_Timeout(int fd, long timeout); 1367 1368 JNIEXPORT jint JNICALL 1369 JVM_Listen(jint fd, jint count); 1370 1371 JNIEXPORT jint JNICALL 1372 JVM_Connect(jint fd, struct sockaddr *him, jint len); 1373 1374 JNIEXPORT jint JNICALL 1375 JVM_Bind(jint fd, struct sockaddr *him, jint len); 1376 1377 JNIEXPORT jint JNICALL 1378 JVM_Accept(jint fd, struct sockaddr *him, jint *len); 1379 1380 JNIEXPORT jint JNICALL 1381 JVM_RecvFrom(jint fd, char *buf, int nBytes, 1382 int flags, struct sockaddr *from, int *fromlen); 1383 1384 JNIEXPORT jint JNICALL 1385 JVM_SendTo(jint fd, char *buf, int len, 1386 int flags, struct sockaddr *to, int tolen); 1387 1388 JNIEXPORT jint JNICALL 1389 JVM_SocketAvailable(jint fd, jint *result); 1390 1391 1392 JNIEXPORT jint JNICALL 1393 JVM_GetSockName(jint fd, struct sockaddr *him, int *len); 1394 1395 JNIEXPORT jint JNICALL 1396 JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen); 1397 1398 JNIEXPORT jint JNICALL 1399 JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen); 1400 1401 JNIEXPORT int JNICALL 1402 JVM_GetHostName(char* name, int namelen); 1403 1404 /* 1405 * The standard printing functions supported by the Java VM. (Should they 1406 * be renamed to JVM_* in the future? 1407 */ 1408 1409 /* 1410 * BE CAREFUL! The following functions do not implement the 1411 * full feature set of standard C printf formats. 1412 */ 1413 JNIEXPORT int 1414 jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args); 1415 1416 JNIEXPORT int 1417 jio_snprintf(char *str, size_t count, const char *fmt, ...); 1418 1419 JNIEXPORT int 1420 jio_fprintf(FILE *, const char *fmt, ...); 1421 1422 JNIEXPORT int 1423 jio_vfprintf(FILE *, const char *fmt, va_list args); 1424 1425 1426 JNIEXPORT void * JNICALL 1427 JVM_RawMonitorCreate(void); 1428 1429 JNIEXPORT void JNICALL 1430 JVM_RawMonitorDestroy(void *mon); 1431 1432 JNIEXPORT jint JNICALL 1433 JVM_RawMonitorEnter(void *mon); 1434 1435 JNIEXPORT void JNICALL 1436 JVM_RawMonitorExit(void *mon); 1437 1438 /* 1439 * java.lang.reflect.Method 1440 */ 1441 JNIEXPORT jobject JNICALL 1442 JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0); 1443 1444 /* 1445 * java.lang.reflect.Constructor 1446 */ 1447 JNIEXPORT jobject JNICALL 1448 JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0); 1449 1450 /* 1451 * java.lang.management support 1452 */ 1453 JNIEXPORT void* JNICALL 1454 JVM_GetManagement(jint version); 1455 1456 /* 1457 * com.sun.tools.attach.VirtualMachine support 1458 * 1459 * Initialize the agent properties with the properties maintained in the VM. 1460 */ 1461 JNIEXPORT jobject JNICALL 1462 JVM_InitAgentProperties(JNIEnv *env, jobject agent_props); 1463 1464 /* Generics reflection support. 1465 * 1466 * Returns information about the given class's EnclosingMethod 1467 * attribute, if present, or null if the class had no enclosing 1468 * method. 1469 * 1470 * If non-null, the returned array contains three elements. Element 0 1471 * is the java.lang.Class of which the enclosing method is a member, 1472 * and elements 1 and 2 are the java.lang.Strings for the enclosing 1473 * method's name and descriptor, respectively. 1474 */ 1475 JNIEXPORT jobjectArray JNICALL 1476 JVM_GetEnclosingMethodInfo(JNIEnv* env, jclass ofClass); 1477 1478 /* 1479 * Java thread state support 1480 */ 1481 enum { 1482 JAVA_THREAD_STATE_NEW = 0, 1483 JAVA_THREAD_STATE_RUNNABLE = 1, 1484 JAVA_THREAD_STATE_BLOCKED = 2, 1485 JAVA_THREAD_STATE_WAITING = 3, 1486 JAVA_THREAD_STATE_TIMED_WAITING = 4, 1487 JAVA_THREAD_STATE_TERMINATED = 5, 1488 JAVA_THREAD_STATE_COUNT = 6 1489 }; 1490 1491 /* 1492 * Returns an array of the threadStatus values representing the 1493 * given Java thread state. Returns NULL if the VM version is 1494 * incompatible with the JDK or doesn't support the given 1495 * Java thread state. 1496 */ 1497 JNIEXPORT jintArray JNICALL 1498 JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState); 1499 1500 /* 1501 * Returns an array of the substate names representing the 1502 * given Java thread state. Returns NULL if the VM version is 1503 * incompatible with the JDK or the VM doesn't support 1504 * the given Java thread state. 1505 * values must be the jintArray returned from JVM_GetThreadStateValues 1506 * and javaThreadState. 1507 */ 1508 JNIEXPORT jobjectArray JNICALL 1509 JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values); 1510 1511 /* ========================================================================= 1512 * The following defines a private JVM interface that the JDK can query 1513 * for the JVM version and capabilities. sun.misc.Version defines 1514 * the methods for getting the VM version and its capabilities. 1515 * 1516 * When a new bit is added, the following should be updated to provide 1517 * access to the new capability: 1518 * HS: JVM_GetVersionInfo and Abstract_VM_Version class 1519 * SDK: Version class 1520 * 1521 * Similary, a private JDK interface JDK_GetVersionInfo0 is defined for 1522 * JVM to query for the JDK version and capabilities. 1523 * 1524 * When a new bit is added, the following should be updated to provide 1525 * access to the new capability: 1526 * HS: JDK_Version class 1527 * SDK: JDK_GetVersionInfo0 1528 * 1529 * ========================================================================== 1530 */ 1531 typedef struct { 1532 /* HotSpot Express VM version string: 1533 * <major>.<minor>-bxx[-<identifier>][-<debug_flavor>] 1534 */ 1535 unsigned int jvm_version; /* Consists of major.minor.0.build */ 1536 unsigned int update_version : 8; /* 0 in HotSpot Express VM */ 1537 unsigned int special_update_version : 8; /* 0 in HotSpot Express VM */ 1538 unsigned int reserved1 : 16; 1539 unsigned int reserved2; 1540 1541 /* The following bits represents JVM supports that JDK has dependency on. 1542 * JDK can use these bits to determine which JVM version 1543 * and support it has to maintain runtime compatibility. 1544 * 1545 * When a new bit is added in a minor or update release, make sure 1546 * the new bit is also added in the main/baseline. 1547 */ 1548 unsigned int is_attachable : 1; 1549 unsigned int is_kernel_jvm : 1; 1550 unsigned int : 30; 1551 unsigned int : 32; 1552 unsigned int : 32; 1553 } jvm_version_info; 1554 1555 #define JVM_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) 1556 #define JVM_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) 1557 // Micro version is 0 in HotSpot Express VM (set in jvm.cpp). 1558 #define JVM_VERSION_MICRO(version) ((version & 0x0000FF00) >> 8) 1559 /* Build number is available in all HotSpot Express VM builds. 1560 * It is defined in make/hotspot_version file. 1561 */ 1562 #define JVM_VERSION_BUILD(version) ((version & 0x000000FF)) 1563 1564 JNIEXPORT void JNICALL 1565 JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size); 1566 1567 typedef struct { 1568 // Naming convention of RE build version string: n.n.n[_uu[c]][-<identifier>]-bxx 1569 unsigned int jdk_version; /* Consists of major, minor, micro (n.n.n) */ 1570 /* and build number (xx) */ 1571 unsigned int update_version : 8; /* Update release version (uu) */ 1572 unsigned int special_update_version : 8; /* Special update release version (c)*/ 1573 unsigned int reserved1 : 16; 1574 unsigned int reserved2; 1575 1576 /* The following bits represents new JDK supports that VM has dependency on. 1577 * VM implementation can use these bits to determine which JDK version 1578 * and support it has to maintain runtime compatibility. 1579 * 1580 * When a new bit is added in a minor or update release, make sure 1581 * the new bit is also added in the main/baseline. 1582 */ 1583 unsigned int thread_park_blocker : 1; 1584 unsigned int post_vm_init_hook_enabled : 1; 1585 unsigned int pending_list_uses_discovered_field : 1; 1586 unsigned int : 29; 1587 unsigned int : 32; 1588 unsigned int : 32; 1589 } jdk_version_info; 1590 1591 #define JDK_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) 1592 #define JDK_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) 1593 #define JDK_VERSION_MICRO(version) ((version & 0x0000FF00) >> 8) 1594 1595 /* Build number is available only for RE build (i.e. JDK_BUILD_NUMBER is set to bNN) 1596 * It will be zero for internal builds. 1597 */ 1598 #define JDK_VERSION_BUILD(version) ((version & 0x000000FF)) 1599 1600 /* 1601 * This is the function JDK_GetVersionInfo0 defined in libjava.so 1602 * that is dynamically looked up by JVM. 1603 */ 1604 typedef void (*jdk_version_info_fn_t)(jdk_version_info* info, size_t info_size); 1605 1606 /* 1607 * This structure is used by the launcher to get the default thread 1608 * stack size from the VM using JNI_GetDefaultJavaVMInitArgs() with a 1609 * version of 1.1. As it is not supported otherwise, it has been removed 1610 * from jni.h 1611 */ 1612 typedef struct JDK1_1InitArgs { 1613 jint version; 1614 1615 char **properties; 1616 jint checkSource; 1617 jint nativeStackSize; 1618 jint javaStackSize; 1619 jint minHeapSize; 1620 jint maxHeapSize; 1621 jint verifyMode; 1622 char *classpath; 1623 1624 jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args); 1625 void (JNICALL *exit)(jint code); 1626 void (JNICALL *abort)(void); 1627 1628 jint enableClassGC; 1629 jint enableVerboseGC; 1630 jint disableAsyncGC; 1631 jint verbose; 1632 jboolean debugging; 1633 jint debugPort; 1634 } JDK1_1InitArgs; 1635 1636 #ifdef __cplusplus 1637 } /* extern "C" */ 1638 #endif /* __cplusplus */ 1639 1640 #endif /* !_JAVASOFT_JVM_H_ */ 1641 1642 #endif // SHARE_VM_PRIMS_JVM_H