Changeset 1391 for branches/GNU/src/gcc/libjava/java/lang/natClass.cc
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (22 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
libjava/java/lang/natClass.cc (modified) (43 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libjava/java/lang/natClass.cc
-
Property cvs2svn:cvs-rev
changed from
1.1to1.1.1.2
r1390 r1391 1 1 // natClass.cc - Implementation of java.lang.Class native methods. 2 2 3 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation3 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation 4 4 5 5 This file is part of libgcj. … … 37 37 #include <java/lang/IllegalArgumentException.h> 38 38 #include <java/lang/IncompatibleClassChangeError.h> 39 39 40 #include <java/lang/InstantiationException.h> 40 41 #include <java/lang/NoClassDefFoundError.h> … … 48 49 #include <java/lang/SecurityManager.h> 49 50 #include <java/lang/StringBuffer.h> 51 50 52 #include <gcj/method.h> 53 54 51 55 52 56 #include <java-cpool.h> 53 54 55 56 57 // FIXME: remove these.58 #define CloneableClass java::lang::Cloneable::class$59 #define ObjectClass java::lang::Object::class$60 #define ErrorClass java::lang::Error::class$61 #define ClassClass java::lang::Class::class$62 #define MethodClass java::lang::reflect::Method::class$63 #define FieldClass java::lang::reflect::Field::class$64 #define ConstructorClass java::lang::reflect::Constructor::class$65 57 66 58 … … 85 77 throw new java::lang::ClassNotFoundException (className); 86 78 87 // FIXME: should use bootstrap class loader if loader is null.88 79 jclass klass = (buffer[0] == '[' 89 80 ? _Jv_FindClassFromSignature (name->data, loader) … … 102 93 java::lang::Class::forName (jstring className) 103 94 { 104 // FIXME: should use class loader from calling method. 105 return forName (className, true, NULL); 95 java::lang::ClassLoader *loader = NULL; 96 gnu::gcj::runtime::StackTrace *t 97 = new gnu::gcj::runtime::StackTrace(4); 98 java::lang::Class *klass = NULL; 99 try 100 { 101 for (int i = 1; !klass; i++) 102 { 103 klass = t->classAt (i); 104 } 105 loader = klass->getClassLoader(); 106 } 107 catch (::java::lang::ArrayIndexOutOfBoundsException *e) 108 { 109 } 110 111 return forName (className, true, loader); 106 112 } 107 113 … … 177 183 JArray<java::lang::reflect::Constructor *> *result 178 184 = (JArray<java::lang::reflect::Constructor *> *) 179 JvNewObjectArray (numConstructors, &ConstructorClass, NULL); 185 JvNewObjectArray (numConstructors, 186 &java::lang::reflect::Constructor::class$, 187 NULL); 180 188 java::lang::reflect::Constructor** cptr = elements (result); 181 189 for (i = 0; i < max; i++) … … 276 284 JArray<java::lang::reflect::Field *> *result 277 285 = (JArray<java::lang::reflect::Field *> *) 278 JvNewObjectArray (field_count, & FieldClass, NULL);286 JvNewObjectArray (field_count, &, NULL); 279 287 java::lang::reflect::Field** fptr = elements (result); 280 288 for (int i = 0; i < field_count; i++) … … 327 335 328 336 java::lang::reflect::Method * 329 java::lang::Class:: getDeclaredMethod (jstring name,330 JArray<jclass> *param_types)337 java::lang::Class::getDeclaredMethod (jstring name, 338 JArray<jclass> *param_types) 331 339 { 332 340 jstring partial_sig = getSignature (param_types, false); … … 336 344 while (--i >= 0) 337 345 { 338 // FIXME: access checks.339 346 if (_Jv_equalUtf8Consts (methods[i].name, utf_name) 340 && _Jv_equaln (methods[i].signature, partial_sig, p_len)) 347 && _Jv_equaln (methods[i].signature, partial_sig, p_len) 348 && (methods[i].accflags 349 & java::lang::reflect::Modifier::INVISIBLE) == 0) 341 350 { 342 351 // Found it. … … 348 357 } 349 358 } 350 throw new java::lang::NoSuchMethodException;359 ; 351 360 } 352 361 … … 363 372 || _Jv_equalUtf8Consts (method->name, clinit_name) 364 373 || _Jv_equalUtf8Consts (method->name, init_name) 365 || _Jv_equalUtf8Consts (method->name, finit_name)) 374 || _Jv_equalUtf8Consts (method->name, finit_name) 375 || (methods[i].accflags 376 & java::lang::reflect::Modifier::INVISIBLE) != 0) 366 377 continue; 367 378 numMethods++; … … 369 380 JArray<java::lang::reflect::Method *> *result 370 381 = (JArray<java::lang::reflect::Method *> *) 371 JvNewObjectArray (numMethods, & MethodClass, NULL);382 JvNewObjectArray (numMethods, &, NULL); 372 383 java::lang::reflect::Method** mptr = elements (result); 373 384 for (i = 0; i < max; i++) … … 377 388 || _Jv_equalUtf8Consts (method->name, clinit_name) 378 389 || _Jv_equalUtf8Consts (method->name, init_name) 379 || _Jv_equalUtf8Consts (method->name, finit_name)) 390 || _Jv_equalUtf8Consts (method->name, finit_name) 391 || (methods[i].accflags 392 & java::lang::reflect::Modifier::INVISIBLE) != 0) 380 393 continue; 381 394 java::lang::reflect::Method* rmethod … … 405 418 // empty array. 406 419 JArray<jclass> *result 407 = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL); 420 = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$, 421 NULL); 408 422 return result; 409 423 } … … 416 430 // empty array. 417 431 JArray<jclass> *result 418 = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL); 432 = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$, 433 NULL); 419 434 return result; 420 435 } … … 477 492 JArray<java::lang::reflect::Field *> *result 478 493 = ((JArray<java::lang::reflect::Field *> *) 479 JvNewObjectArray (count, & FieldClass, NULL));494 JvNewObjectArray (count, &, NULL)); 480 495 481 496 _getFields (result, 0); … … 495 510 496 511 java::lang::reflect::Method * 497 java::lang::Class:: getMethod (jstring name, JArray<jclass> *param_types)512 java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types) 498 513 { 499 514 jstring partial_sig = getSignature (param_types, false); … … 507 522 // FIXME: access checks. 508 523 if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name) 509 && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len)) 524 && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len) 525 && (klass->methods[i].accflags 526 & java::lang::reflect::Modifier::INVISIBLE) == 0) 510 527 { 511 528 // Found it. … … 524 541 } 525 542 } 526 throw new java::lang::NoSuchMethodException; 543 544 // If we haven't found a match, and this class is an interface, then 545 // check all the superinterfaces. 546 if (isInterface()) 547 { 548 for (int i = 0; i < interface_count; ++i) 549 { 550 using namespace java::lang::reflect; 551 Method *rmethod = interfaces[i]->_getMethod (name, param_types); 552 if (rmethod != NULL) 553 return rmethod; 554 } 555 } 556 557 return NULL; 527 558 } 528 559 … … 544 575 || _Jv_equalUtf8Consts (method->name, clinit_name) 545 576 || _Jv_equalUtf8Consts (method->name, init_name) 546 || _Jv_equalUtf8Consts (method->name, finit_name)) 577 || _Jv_equalUtf8Consts (method->name, finit_name) 578 || (method->accflags 579 & java::lang::reflect::Modifier::INVISIBLE) != 0) 547 580 continue; 548 581 // Only want public methods. … … 617 650 618 651 JArray<Method *> *result 619 = ((JArray<Method *> *) JvNewObjectArray (count, &MethodClass, NULL)); 652 = ((JArray<Method *> *) JvNewObjectArray (count, 653 &Method::class$, 654 NULL)); 620 655 621 656 // When filling the array for real, we get the actual count. Then … … 626 661 { 627 662 JArray<Method *> *r2 628 = ((JArray<Method *> *) JvNewObjectArray (real_count, &MethodClass, 663 = ((JArray<Method *> *) JvNewObjectArray (real_count, 664 &Method::class$, 629 665 NULL)); 630 666 … … 666 702 // FIXME: we special-case one check here just to pass a Plum Hall 667 703 // test. Once access checking is implemented, remove this. 668 if (this == & ClassClass)704 if (this == &) 669 705 throw new java::lang::IllegalAccessException; 670 706 … … 735 771 736 772 // Steps 3 & 4. 737 if (state == JV_STATE_DONE 738 || state == JV_STATE_IN_PROGRESS 739 || thread == self) 773 if (state == JV_STATE_DONE || state == JV_STATE_IN_PROGRESS) 740 774 { 741 775 _Jv_MonitorExit (this); … … 747 781 { 748 782 _Jv_MonitorExit (this); 749 throw new java::lang::NoClassDefFoundError ;783 throw new java::lang::NoClassDefFoundError; 750 784 } 751 785 … … 783 817 catch (java::lang::Throwable *except) 784 818 { 785 if (! ErrorClass.isInstance(except))819 if (! .isInstance(except)) 786 820 { 787 821 try … … 876 910 _Jv_Method *method) 877 911 { 878 _Jv_MonitorEnter (& ClassClass);912 _Jv_MonitorEnter (&); 879 913 880 914 int index = method->name->hash & MCACHE_SIZE; … … 883 917 method_cache[index].klass = klass; 884 918 885 _Jv_MonitorExit (& ClassClass);919 _Jv_MonitorExit (&); 886 920 } 887 921 … … 933 967 if (source == target) 934 968 return true; 935 969 936 970 // If target is array, so must source be. 937 if(target->isArray ())971 (target->isArray ()) 938 972 { 939 973 if (! source->isArray()) 940 974 return false; 941 return _Jv_IsAssignableFrom(target->getComponentType(),942 source->getComponentType());975 976 ); 943 977 } 944 978 … … 950 984 (source->idt == NULL || source->isInterface(), false)) 951 985 return _Jv_InterfaceAssignableFrom (target, source); 952 986 953 987 _Jv_IDispatchTable *cl_idt = source->idt; 954 988 _Jv_IDispatchTable *if_idt = target->idt; … … 966 1000 return false; 967 1001 } 968 1002 969 1003 // Primitive TYPE classes are only assignable to themselves. 970 if (__builtin_expect (target->isPrimitive() , false))1004 if (__builtin_expect (target->isPrimitive(), false)) 971 1005 return false; 972 973 if (target == &ObjectClass) 974 { 975 if (source->isPrimitive()) 976 return false; 977 return true; 978 } 979 else if (source->ancestors != NULL 980 && target->ancestors != NULL 981 && source->depth >= target->depth 1006 1007 if (target == &java::lang::Object::class$) 1008 return true; 1009 else if (source->ancestors == NULL || target->ancestors == NULL) 1010 { 1011 // We need this case when either SOURCE or TARGET has not has 1012 // its constant-time tables prepared. 1013 1014 // At this point we know that TARGET can't be Object, so it is 1015 // safe to use that as the termination point. 1016 while (source && source != &java::lang::Object::class$) 1017 { 1018 if (source == target) 1019 return true; 1020 source = source->getSuperclass(); 1021 } 1022 } 1023 else if (source->depth >= target->depth 982 1024 && source->ancestors[source->depth - target->depth] == target) 983 1025 return true; 984 1026 985 1027 return false; 986 1028 } … … 1037 1079 JvAssert (arr != NULL); 1038 1080 jclass elt_class = (JV_CLASS (arr))->getComponentType(); 1081 1082 1039 1083 jclass obj_class = JV_CLASS (obj); 1040 1084 if (__builtin_expect 1041 1085 (! _Jv_IsAssignableFrom (elt_class, obj_class), false)) 1042 throw new java::lang::ArrayStoreException; 1086 throw new java::lang::ArrayStoreException 1087 ((new java::lang::StringBuffer 1088 (JvNewStringUTF("Cannot store ")))->append 1089 (obj_class->getName())->append 1090 (JvNewStringUTF(" in array of type "))->append 1091 (elt_class->getName())->toString()); 1043 1092 } 1044 1093 } … … 1071 1120 jclass klass0 = klass; 1072 1121 jboolean has_interfaces = 0; 1073 while (klass0 != & ObjectClass)1122 while (klass0 != &) 1074 1123 { 1075 1124 has_interfaces += klass0->interface_count; … … 1314 1363 1315 1364 static _Jv_Mutex_t iindex_mutex; 1316 bool iindex_mutex_initialized = false;1365 bool iindex_mutex_initialized = false; 1317 1366 1318 1367 // We need to find the correct offset in the Class Interface Dispatch … … 1528 1577 1529 1578 // Returns true if METH should get an entry in a VTable. 1530 static bool1579 static 1531 1580 isVirtualMethod (_Jv_Method *meth) 1532 1581 { … … 1534 1583 return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0) 1535 1584 && meth->name->data[0] != '<'); 1585 1586 1587 1588 1589 1590 1591 1536 1592 } 1537 1593 … … 1546 1602 || klass->vtable_method_count != -1) 1547 1603 return; 1548 1604 1549 1605 jclass superclass = klass->superclass; 1550 1606 … … 1554 1610 _Jv_LayoutVTableMethods (superclass); 1555 1611 } 1556 1612 1557 1613 int index = (superclass == NULL ? 0 : superclass->vtable_method_count); 1558 1614 … … 1561 1617 _Jv_Method *meth = &klass->methods[i]; 1562 1618 _Jv_Method *super_meth = NULL; 1563 1564 if (! isVirtualMethod(meth))1565 continue;1566 1619 1620 if (!(meth)) 1621 continue; 1622 1567 1623 if (superclass != NULL) 1568 super_meth = _Jv_LookupDeclaredMethod (superclass, meth->name, 1569 meth->signature); 1570 1624 { 1625 super_meth = _Jv_LookupDeclaredMethod (superclass, meth->name, 1626 meth->signature); 1627 } 1628 1571 1629 if (super_meth) 1572 1630 meth->index = super_meth->index; 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1573 1662 else 1574 meth->index = index++; 1575 } 1576 1577 klass->vtable_method_count = index; 1578 } 1579 1580 // Set entries in VTABLE for virtual methods declared in KLASS. If KLASS has 1581 // an immediate abstract parent, recursivly do its methods first. 1582 void 1583 _Jv_SetVTableEntries (jclass klass, _Jv_VTable *vtable) 1584 { 1585 using namespace java::lang::reflect; 1586 1587 jclass superclass = klass->getSuperclass(); 1588 1589 if (superclass != NULL && (superclass->getModifiers() & Modifier::ABSTRACT)) 1590 _Jv_SetVTableEntries (superclass, vtable); 1591 1592 for (int i = klass->method_count - 1; i >= 0; i--) 1593 { 1594 _Jv_Method *meth = &klass->methods[i]; 1595 if (!isVirtualMethod(meth)) 1596 continue; 1597 vtable->set_method(meth->index, meth->ncode); 1663 { 1664 vtable->set_method(meth->index, meth->ncode); 1665 flags[meth->index] = true; 1666 } 1598 1667 } 1599 1668 } … … 1611 1680 || (klass->accflags & Modifier::ABSTRACT)) 1612 1681 return; 1613 1682 1614 1683 // out before we can create a vtable. 1615 1684 if (klass->vtable_method_count == -1) … … 1619 1688 _Jv_VTable *vtable = _Jv_VTable::new_vtable (klass->vtable_method_count); 1620 1689 klass->vtable = vtable; 1621 1690 1691 jboolean flags[klass->vtable_method_count]; 1692 for (int i = 0; i < klass->vtable_method_count; ++i) 1693 flags[i] = false; 1694 1622 1695 // Copy the vtable of the closest non-abstract superclass. 1623 1696 jclass superclass = klass->superclass; … … 1634 1707 1635 1708 for (int i = 0; i < superclass->vtable_method_count; ++i) 1636 vtable->set_method (i, superclass->vtable->get_method (i)); 1709 { 1710 vtable->set_method (i, superclass->vtable->get_method (i)); 1711 flags[i] = true; 1712 } 1637 1713 } 1638 1714 … … 1643 1719 // For each virtual declared in klass and any immediate abstract 1644 1720 // superclasses, set new vtable entry or override an old one. 1645 _Jv_SetVTableEntries (klass, vtable); 1646 } 1721 _Jv_SetVTableEntries (klass, vtable, flags); 1722 1723 // It is an error to have an abstract method in a concrete class. 1724 if (! (klass->accflags & Modifier::ABSTRACT)) 1725 { 1726 for (int i = 0; i < klass->vtable_method_count; ++i) 1727 if (! flags[i]) 1728 // FIXME: messsage. 1729 throw new java::lang::AbstractMethodError (); 1730 } 1731 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
