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