This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: annotate source with __builtin_expect _and_ install jvmpi.h



Two patches in one.

The first is a revision of the __builtin_expect patch.  It is always
disabled.  We can enable it with a configure test when the compiler is
fixed.

The second is something I should have done a long time ago, which is
to install jvmpi.h.

I am checking this in.

2000-04-22  Anthony Green  <green@cygnus.com>

	* include/jvm.h (__builtin_expect): Define as unused for now.
	* java/lang/natObject.cc (_Jv_MonitorEnter): Add __builtin_expect.
	(notify): Ditto.
	(notifyAll): Ditto.
	(wait): Ditto.
	(_Jv_MonitorExit): Ditto.
	* boehm.cc (_Jv_MarkObj): Ditto.
	(_Jv_MarkObj): Ditto.
	(_Jv_MarkArray): Ditto.
	(_Jv_AllocBytes): Ditto.
	* prims.cc (_Jv_AllocObject): Ditto.
	(_Jv_NewObjectArray): Ditto.
	(_Jv_NewPrimArray): Ditto.
	(_Jv_Malloc): Ditto.
	(_Jv_Realloc): Ditto.
	(_Jv_MallocUnchecked): Ditto.
	(_Jv_divI): Ditto.
	(_Jv_remI): Ditto.
	(_Jv_divJ): Ditto.
	(_Jv_remJ): Ditto.

	* include/Makefile.in: Rebuilt.
	* include/Makefile.am (include_HEADERS): Add jvmpi.h.

Index: libjava/boehm.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/boehm.cc,v
retrieving revision 1.17
diff -c -r1.17 boehm.cc
*** boehm.cc	2000/04/19 10:10:39	1.17
--- boehm.cc	2000/04/22 16:21:24
***************
*** 87,93 ****
    _Jv_VTable *dt = *(_Jv_VTable **) addr;
    // We check this in case a GC occurs before the vtbl is set.  FIXME:
    // should use allocation lock while initializing object.
!   if (! dt)
      return mark_stack_ptr;
    jclass klass = dt->clas;
  
--- 87,93 ----
    _Jv_VTable *dt = *(_Jv_VTable **) addr;
    // We check this in case a GC occurs before the vtbl is set.  FIXME:
    // should use allocation lock while initializing object.
!   if (__builtin_expect (! dt, 0))
      return mark_stack_ptr;
    jclass klass = dt->clas;
  
***************
*** 98,104 ****
    p = (ptr_t) klass;
    MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj, o2label);
  
!   if (klass == &ClassClass)
      {
        jclass c = (jclass) addr;
  
--- 98,104 ----
    p = (ptr_t) klass;
    MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj, o2label);
  
!   if (__builtin_expect (klass == &ClassClass, 0))
      {
        jclass c = (jclass) addr;
  
***************
*** 281,287 ****
    _Jv_VTable *dt = *(_Jv_VTable **) addr;
    // We check this in case a GC occurs before the vtbl is set.  FIXME:
    // should use allocation lock while initializing object.
!   if (! dt)
      return mark_stack_ptr;
    jclass klass = dt->clas;
  
--- 281,287 ----
    _Jv_VTable *dt = *(_Jv_VTable **) addr;
    // We check this in case a GC occurs before the vtbl is set.  FIXME:
    // should use allocation lock while initializing object.
!   if (__builtin_expect (! dt, 0))
      return mark_stack_ptr;
    jclass klass = dt->clas;
  
***************
*** 329,335 ****
    // guarantee that PTRFREE allocations are zeroed.  Note that we
    // don't have to do this for other allocation types because we set
    // the `ok_init' flag in the type descriptor.
!   if (r != NULL)
      memset (r, 0, size);
    return r;
  }
--- 329,335 ----
    // guarantee that PTRFREE allocations are zeroed.  Note that we
    // don't have to do this for other allocation types because we set
    // the `ok_init' flag in the type descriptor.
!   if (__builtin_expect (r != NULL, !NULL))
      memset (r, 0, size);
    return r;
  }
Index: libjava/prims.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/prims.cc,v
retrieving revision 1.25
diff -c -r1.25 prims.cc
*** prims.cc	2000/04/02 15:34:17	1.25
--- prims.cc	2000/04/22 16:21:25
***************
*** 322,328 ****
    _Jv_InitClass (c);
  
    jobject obj = (jobject) _Jv_AllocObj (size);
!   if (! obj)
      JvThrow (no_memory);
    *((_Jv_VTable **) obj) = c->vtable;
  
--- 322,328 ----
    _Jv_InitClass (c);
  
    jobject obj = (jobject) _Jv_AllocObj (size);
!   if (__builtin_expect (! obj, 0))
      JvThrow (no_memory);
    *((_Jv_VTable **) obj) = c->vtable;
  
***************
*** 339,345 ****
  #ifdef ENABLE_JVMPI
    // Service JVMPI request.
  
!   if (_Jv_JVMPI_Notify_OBJECT_ALLOC)
      {
        JVMPI_Event event;
  
--- 339,345 ----
  #ifdef ENABLE_JVMPI
    // Service JVMPI request.
  
!   if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC != 0, 0))
      {
        JVMPI_Event event;
  
***************
*** 366,372 ****
  jobjectArray
  _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
  {
!   if (count < 0)
      JvThrow (new java::lang::NegativeArraySizeException);
  
    JvAssert (! elementClass->isPrimitive ());
--- 366,372 ----
  jobjectArray
  _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
  {
!   if (__builtin_expect (count < 0, 0))
      JvThrow (new java::lang::NegativeArraySizeException);
  
    JvAssert (! elementClass->isPrimitive ());
***************
*** 376,382 ****
  							     elementClass);
  
    // Check for overflow.
!   if ((size_t) count > (SIZE_T_MAX - size) / sizeof (jobject))
      JvThrow (no_memory);
  
    size += count * sizeof (jobject);
--- 376,383 ----
  							     elementClass);
  
    // Check for overflow.
!   if (__builtin_expect ((size_t) count > 
! 			(SIZE_T_MAX - size) / sizeof (jobject), 0));
      JvThrow (no_memory);
  
    size += count * sizeof (jobject);
***************
*** 385,391 ****
    jclass clas = _Jv_FindArrayClass (elementClass, 0);
  
    obj = (jobjectArray) _Jv_AllocArray (size);
!   if (! obj)
      JvThrow (no_memory);
    obj->length = count;
    jobject* ptr = elements(obj);
--- 386,392 ----
    jclass clas = _Jv_FindArrayClass (elementClass, 0);
  
    obj = (jobjectArray) _Jv_AllocArray (size);
!   if (__builtin_expect (! obj, 0))
      JvThrow (no_memory);
    obj->length = count;
    jobject* ptr = elements(obj);
***************
*** 409,415 ****
  _Jv_NewPrimArray (jclass eltype, jint count)
  {
    int elsize = eltype->size();
!   if (count < 0)
      JvThrow (new java::lang::NegativeArraySizeException ());
  
    JvAssert (eltype->isPrimitive ());
--- 410,416 ----
  _Jv_NewPrimArray (jclass eltype, jint count)
  {
    int elsize = eltype->size();
!   if (__builtin_expect (count < 0, 0))
      JvThrow (new java::lang::NegativeArraySizeException ());
  
    JvAssert (eltype->isPrimitive ());
***************
*** 417,427 ****
    size_t size = (size_t) _Jv_GetArrayElementFromElementType (dummy, eltype);
  
    // Check for overflow.
!   if ((size_t) count > (SIZE_T_MAX - size) / elsize)
      JvThrow (no_memory);
  
    __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count);
!   if (! arr)
      JvThrow (no_memory);
    arr->length = count;
    // Note that we assume we are given zeroed memory by the allocator.
--- 418,429 ----
    size_t size = (size_t) _Jv_GetArrayElementFromElementType (dummy, eltype);
  
    // Check for overflow.
!   if (__builtin_expect ((size_t) count > 
! 			(SIZE_T_MAX - size) / elsize, 0))
      JvThrow (no_memory);
  
    __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count);
!   if (__builtin_expect (! arr, 0))
      JvThrow (no_memory);
    arr->length = count;
    // Note that we assume we are given zeroed memory by the allocator.
***************
*** 924,933 ****
  void *
  _Jv_Malloc (jsize size)
  {
!   if (size == 0)
      size = 1;
    void *ptr = malloc ((size_t) size);
!   if (ptr == NULL)
      JvThrow (no_memory);
    return ptr;
  }
--- 926,935 ----
  void *
  _Jv_Malloc (jsize size)
  {
!   if (__builtin_expect (size == 0, 0))
      size = 1;
    void *ptr = malloc ((size_t) size);
!   if (__builtin_expect (ptr == NULL, 0))
      JvThrow (no_memory);
    return ptr;
  }
***************
*** 935,944 ****
  void *
  _Jv_Realloc (void *ptr, jsize size)
  {
!   if (size == 0)
      size = 1;
    ptr = realloc (ptr, (size_t) size);
!   if (ptr == NULL)
      JvThrow (no_memory);
    return ptr;
  }
--- 937,946 ----
  void *
  _Jv_Realloc (void *ptr, jsize size)
  {
!   if (__builtin_expect (size == 0, 0))
      size = 1;
    ptr = realloc (ptr, (size_t) size);
!   if (__builtin_expect (ptr == NULL, 0))
      JvThrow (no_memory);
    return ptr;
  }
***************
*** 946,952 ****
  void *
  _Jv_MallocUnchecked (jsize size)
  {
!   if (size == 0)
      size = 1;
    return malloc ((size_t) size);
  }
--- 948,954 ----
  void *
  _Jv_MallocUnchecked (jsize size)
  {
!   if (__builtin_expect (size == 0, 0))
      size = 1;
    return malloc ((size_t) size);
  }
***************
*** 967,973 ****
  jint
  _Jv_divI (jint dividend, jint divisor)
  {
!   if (divisor == 0)
      _Jv_Throw (arithexception);
    
    if (dividend == (jint) 0x80000000L && divisor == -1)
--- 969,975 ----
  jint
  _Jv_divI (jint dividend, jint divisor)
  {
!   if (__builtin_expect (divisor == 0, 0))
      _Jv_Throw (arithexception);
    
    if (dividend == (jint) 0x80000000L && divisor == -1)
***************
*** 979,985 ****
  jint
  _Jv_remI (jint dividend, jint divisor)
  {
!   if (divisor == 0)
      _Jv_Throw (arithexception);
    
    if (dividend == (jint) 0x80000000L && divisor == -1)
--- 981,987 ----
  jint
  _Jv_remI (jint dividend, jint divisor)
  {
!   if (__builtin_expect (divisor == 0, 0))
      _Jv_Throw (arithexception);
    
    if (dividend == (jint) 0x80000000L && divisor == -1)
***************
*** 991,997 ****
  jlong
  _Jv_divJ (jlong dividend, jlong divisor)
  {
!   if (divisor == 0)
      _Jv_Throw (arithexception);
    
    if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
--- 993,999 ----
  jlong
  _Jv_divJ (jlong dividend, jlong divisor)
  {
!   if (__builtin_expect (divisor == 0, 0))
      _Jv_Throw (arithexception);
    
    if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
***************
*** 1003,1009 ****
  jlong
  _Jv_remJ (jlong dividend, jlong divisor)
  {
!   if (divisor == 0)
      _Jv_Throw (arithexception);
    
    if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
--- 1005,1011 ----
  jlong
  _Jv_remJ (jlong dividend, jlong divisor)
  {
!   if (__builtin_expect (divisor == 0, 0))
      _Jv_Throw (arithexception);
    
    if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
Index: libjava/include/Makefile.am
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/Makefile.am,v
retrieving revision 1.2
diff -c -r1.2 Makefile.am
*** Makefile.am	2000/03/06 02:50:38	1.2
--- Makefile.am	2000/04/22 16:21:25
***************
*** 2,5 ****
  
  AUTOMAKE_OPTIONS = foreign no-installinfo
  
! include_HEADERS = jni.h
--- 2,5 ----
  
  AUTOMAKE_OPTIONS = foreign no-installinfo
  
! include_HEADERS = jni.h jvmpi.h
Index: libjava/include/Makefile.in
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/Makefile.in,v
retrieving revision 1.7
diff -c -r1.7 Makefile.in
*** Makefile.in	2000/03/09 04:50:49	1.7
--- Makefile.in	2000/04/22 16:21:25
***************
*** 116,122 ****
  
  AUTOMAKE_OPTIONS = foreign no-installinfo
  
! include_HEADERS = jni.h
  mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
  CONFIG_HEADER = config.h
  CONFIG_CLEAN_FILES = 
--- 116,122 ----
  
  AUTOMAKE_OPTIONS = foreign no-installinfo
  
! include_HEADERS = jni.h jvmpi.h
  mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
  CONFIG_HEADER = config.h
  CONFIG_CLEAN_FILES = 
***************
*** 127,133 ****
  
  DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
  
! TAR = tar
  GZIP_ENV = --best
  all: all-redirect
  .SUFFIXES:
--- 127,133 ----
  
  DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
  
! TAR = gtar
  GZIP_ENV = --best
  all: all-redirect
  .SUFFIXES:
***************
*** 224,230 ****
  	@for file in $(DISTFILES); do \
  	  d=$(srcdir); \
  	  if test -d $$d/$$file; then \
! 	    cp -pr $$/$$file $(distdir)/$$file; \
  	  else \
  	    test -f $(distdir)/$$file \
  	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
--- 224,230 ----
  	@for file in $(DISTFILES); do \
  	  d=$(srcdir); \
  	  if test -d $$d/$$file; then \
! 	    cp -pr $$d/$$file $(distdir)/$$file; \
  	  else \
  	    test -f $(distdir)/$$file \
  	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
Index: libjava/include/jvm.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/jvm.h,v
retrieving revision 1.22
diff -c -r1.22 jvm.h
*** jvm.h	2000/04/20 22:24:33	1.22
--- jvm.h	2000/04/22 16:21:25
***************
*** 11,16 ****
--- 11,19 ----
  #ifndef __JAVA_JVM_H__
  #define __JAVA_JVM_H__
  
+ // FIXME: __builtin_expect doesn't work yet.
+ #define __builtin_expect(A,B) (A)
+ 
  #include <gcj/javaprims.h>
  
  #include <java-assert.h>
Index: libjava/java/lang/natObject.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natObject.cc,v
retrieving revision 1.10
diff -c -r1.10 natObject.cc
*** natObject.cc	2000/04/09 01:26:20	1.10
--- natObject.cc	2000/04/22 16:21:26
***************
*** 172,181 ****
  void
  java::lang::Object::notify (void)
  {
!   if (INIT_NEEDED (this))
      sync_init ();
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) sync_info;
!   if (_Jv_CondNotify (&si->condition, &si->mutex))
      JvThrow (new IllegalMonitorStateException(JvNewStringLatin1 
                                                ("current thread not owner")));
  }
--- 172,181 ----
  void
  java::lang::Object::notify (void)
  {
!   if (__builtin_expect (INIT_NEEDED (this), 0))
      sync_init ();
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) sync_info;
!   if (__builtin_expect (_Jv_CondNotify (&si->condition, &si->mutex), 0))
      JvThrow (new IllegalMonitorStateException(JvNewStringLatin1 
                                                ("current thread not owner")));
  }
***************
*** 183,192 ****
  void
  java::lang::Object::notifyAll (void)
  {
!   if (INIT_NEEDED (this))
      sync_init ();
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) sync_info;
!   if (_Jv_CondNotifyAll (&si->condition, &si->mutex))
      JvThrow (new IllegalMonitorStateException(JvNewStringLatin1 
                                                ("current thread not owner")));
  }
--- 183,192 ----
  void
  java::lang::Object::notifyAll (void)
  {
!   if (__builtin_expect (INIT_NEEDED (this), 0))
      sync_init ();
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) sync_info;
!   if (__builtin_expect (_Jv_CondNotifyAll (&si->condition, &si->mutex), 0))
      JvThrow (new IllegalMonitorStateException(JvNewStringLatin1 
                                                ("current thread not owner")));
  }
***************
*** 194,202 ****
  void
  java::lang::Object::wait (jlong timeout, jint nanos)
  {
!   if (INIT_NEEDED (this))
      sync_init ();
!   if (timeout < 0 || nanos < 0 || nanos > 999999)
      JvThrow (new IllegalArgumentException);
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) sync_info;
    switch (_Jv_CondWait (&si->condition, &si->mutex, timeout, nanos))
--- 194,202 ----
  void
  java::lang::Object::wait (jlong timeout, jint nanos)
  {
!   if (__builtin_expect (INIT_NEEDED (this), 0))
      sync_init ();
!   if (__builtin_expect (timeout < 0 || nanos < 0 || nanos > 999999, 0))
      JvThrow (new IllegalArgumentException);
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) sync_info;
    switch (_Jv_CondWait (&si->condition, &si->mutex, timeout, nanos))
***************
*** 226,235 ****
  _Jv_MonitorEnter (jobject obj)
  {
  #ifndef HANDLE_SEGV
!   if (! obj)
      JvThrow (new java::lang::NullPointerException);
  #endif
!   if (INIT_NEEDED (obj))
      obj->sync_init ();
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) obj->sync_info;
    return _Jv_MutexLock (&si->mutex);
--- 226,235 ----
  _Jv_MonitorEnter (jobject obj)
  {
  #ifndef HANDLE_SEGV
!   if (__builtin_expect (! obj, 0))
      JvThrow (new java::lang::NullPointerException);
  #endif
!   if (__builtin_expect (INIT_NEEDED (obj), 0))
      obj->sync_init ();
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) obj->sync_info;
    return _Jv_MutexLock (&si->mutex);
***************
*** 241,247 ****
    JvAssert (obj);
    JvAssert (! INIT_NEEDED (obj));
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) obj->sync_info;
!   if (_Jv_MutexUnlock (&si->mutex))
      JvThrow (new java::lang::IllegalMonitorStateException);
    return 0;
  }
--- 241,247 ----
    JvAssert (obj);
    JvAssert (! INIT_NEEDED (obj));
    _Jv_SyncInfo *si = (_Jv_SyncInfo *) obj->sync_info;
!   if (__builtin_expect (_Jv_MutexUnlock (&si->mutex), 0))
      JvThrow (new java::lang::IllegalMonitorStateException);
    return 0;
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]