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_OPTO_TYPE_HPP
26 #define SHARE_VM_OPTO_TYPE_HPP
27
28 #include "ci/ciValueKlass.hpp"
29 #include "opto/adlcVMDeps.hpp"
30 #include "runtime/handles.hpp"
31
32 // Portions of code courtesy of Clifford Click
33
34 // Optimization - Graph Style
35
36
37 // This class defines a Type lattice. The lattice is used in the constant
38 // propagation algorithms, and for some type-checking of the iloc code.
39 // Basic types include RSD's (lower bound, upper bound, stride for integers),
40 // float & double precision constants, sets of data-labels and code-labels.
41 // The complete lattice is described below. Subtypes have no relationship to
42 // up or down in the lattice; that is entirely determined by the behavior of
43 // the MEET/JOIN functions.
44
45 class Dict;
46 class Type;
47 class TypeD;
48 class TypeF;
49 class TypeInt;
50 class TypeLong;
674 const Type ** const _fields; // Array of field types
675
676 public:
677 virtual bool eq( const Type *t ) const;
678 virtual int hash() const; // Type specific hashing
679 virtual bool singleton(void) const; // TRUE if type is a singleton
680 virtual bool empty(void) const; // TRUE if type is vacuous
681
682 // Accessors:
683 uint cnt() const { return _cnt; }
684 const Type* field_at(uint i) const {
685 assert(i < _cnt, "oob");
686 return _fields[i];
687 }
688 void set_field_at(uint i, const Type* t) {
689 assert(i < _cnt, "oob");
690 _fields[i] = t;
691 }
692
693 static const TypeTuple *make( uint cnt, const Type **fields );
694 static const TypeTuple *make_range(ciSignature *sig);
695 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, bool vt_fields_as_args = false);
696
697 // Subroutine call type with space allocated for argument types
698 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
699 static const Type **fields( uint arg_cnt );
700
701 virtual const Type *xmeet( const Type *t ) const;
702 virtual const Type *xdual() const; // Compute dual right now.
703 // Convenience common pre-built types.
704 static const TypeTuple *IFBOTH;
705 static const TypeTuple *IFFALSE;
706 static const TypeTuple *IFTRUE;
707 static const TypeTuple *IFNEITHER;
708 static const TypeTuple *LOOPBODY;
709 static const TypeTuple *MEMBAR;
710 static const TypeTuple *STORECONDITIONAL;
711 static const TypeTuple *START_I2C;
712 static const TypeTuple *INT_PAIR;
713 static const TypeTuple *LONG_PAIR;
714 static const TypeTuple *INT_CC_PAIR;
1327 int instance_id = InstanceBot, const TypePtr* speculative = NULL, int inline_depth = InlineDepthBottom);
1328 // Make a pointer to a value type
1329 static const TypeValueTypePtr* make(PTR ptr, ciValueKlass* vk, ciObject* o = NULL) { return make(TypeValueType::make(vk), ptr, o); }
1330 // Make a pointer to a constant value type
1331 static const TypeValueTypePtr* make(ciObject* o) { return make(TypePtr::Constant, o->klass()->as_value_klass(), o); }
1332
1333 const TypeValueType* value_type() const { return _vt; }
1334
1335 virtual const TypePtr* add_offset(intptr_t offset) const;
1336
1337 virtual const Type* cast_to_ptr_type(PTR ptr) const;
1338 virtual const TypeOopPtr* cast_to_instance_id(int instance_id) const;
1339
1340 virtual bool eq(const Type* t) const;
1341 virtual int hash() const; // Type specific hashing
1342 virtual bool empty(void) const; // TRUE if type is vacuous
1343
1344 virtual const Type* xmeet_helper(const Type* t) const;
1345 virtual const Type* xdual() const;
1346
1347 #ifndef PRODUCT
1348 virtual void dump2(Dict &d, uint depth, outputStream* st) const; // Specialized per-Type dumping
1349 #endif
1350 };
1351
1352 //------------------------------TypeMetadataPtr-------------------------------------
1353 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1354 class TypeMetadataPtr : public TypePtr {
1355 protected:
1356 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset);
1357 // Do not allow interface-vs.-noninterface joins to collapse to top.
1358 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1359 public:
1360 virtual bool eq( const Type *t ) const;
1361 virtual int hash() const; // Type specific hashing
1362 virtual bool singleton(void) const; // TRUE if type is a singleton
1363
1364 private:
1365 ciMetadata* _metadata;
1366
1385 static const TypeMetadataPtr *BOTTOM;
1386
1387 #ifndef PRODUCT
1388 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1389 #endif
1390 };
1391
1392 //------------------------------TypeKlassPtr-----------------------------------
1393 // Class of Java Klass pointers
1394 class TypeKlassPtr : public TypePtr {
1395 TypeKlassPtr(PTR ptr, ciKlass* klass, Offset offset);
1396
1397 protected:
1398 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1399 public:
1400 virtual bool eq( const Type *t ) const;
1401 virtual int hash() const; // Type specific hashing
1402 virtual bool singleton(void) const; // TRUE if type is a singleton
1403 private:
1404
1405 static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1406
1407 ciKlass* _klass;
1408
1409 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1410 bool _klass_is_exact;
1411
1412 public:
1413 ciSymbol* name() const { return klass()->name(); }
1414
1415 ciKlass* klass() const { return _klass; }
1416 bool klass_is_exact() const { return _klass_is_exact; }
1417
1418 bool is_loaded() const { return klass()->is_loaded(); }
1419
1420 // Creates a type given a klass. Correctly handles multi-dimensional arrays
1421 // Respects UseUniqueSubclasses.
1422 // If the klass is final, the resulting type will be exact.
1423 static const TypeKlassPtr* make_from_klass(ciKlass* klass) {
1424 return make_from_klass_common(klass, true, false);
1425 }
1426 // Same as before, but will produce an exact type, even if
1427 // the klass is not final, as long as it has exactly one implementation.
1428 static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) {
1429 return make_from_klass_common(klass, true, true);
1430 }
1431 // Same as before, but does not respects UseUniqueSubclasses.
1432 // Use this only for creating array element types.
1433 static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) {
1434 return make_from_klass_common(klass, false, false);
1435 }
1436
1437 // Make a generic (unclassed) pointer to metadata.
1438 static const TypeKlassPtr* make(PTR ptr, Offset offset);
1439
1440 // ptr to klass 'k'
1441 static const TypeKlassPtr* make(ciKlass* k) { return make( TypePtr::Constant, k, Offset(0)); }
1442 // ptr to klass 'k' with offset
1443 static const TypeKlassPtr* make(ciKlass* k, Offset offset) { return make( TypePtr::Constant, k, offset); }
1444 // ptr to klass 'k' or sub-klass
1445 static const TypeKlassPtr* make(PTR ptr, ciKlass* k, Offset offset);
1446
1447 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1448
1449 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1450
1451 // corresponding pointer to instance, for a given class
1452 const TypeOopPtr* as_instance_type() const;
1453
1454 virtual const TypePtr *add_offset( intptr_t offset ) const;
1455 virtual const Type *xmeet( const Type *t ) const;
1456 virtual const Type *xdual() const; // Compute dual right now.
1572 }
1573
1574 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1575 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1576 }
1577
1578 public:
1579 static const TypeNarrowKlass *make( const TypePtr* type);
1580
1581 // static const TypeNarrowKlass *BOTTOM;
1582 static const TypeNarrowKlass *NULL_PTR;
1583
1584 #ifndef PRODUCT
1585 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1586 #endif
1587 };
1588
1589 //------------------------------TypeFunc---------------------------------------
1590 // Class of Array Types
1591 class TypeFunc : public Type {
1592 TypeFunc(const TypeTuple *domain_sig, const TypeTuple *domain_cc, const TypeTuple *range) : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range(range) {}
1593 virtual bool eq( const Type *t ) const;
1594 virtual int hash() const; // Type specific hashing
1595 virtual bool singleton(void) const; // TRUE if type is a singleton
1596 virtual bool empty(void) const; // TRUE if type is vacuous
1597
1598 // Domains of inputs: value type arguments are not passed by
1599 // reference, instead each field of the value type is passed as an
1600 // argument. We maintain 2 views of the argument list here: one
1601 // based on the signature (with a value type argument as a single
1602 // slot), one based on the actual calling convention (with a value
1603 // type argument as a list of its fields).
1604 const TypeTuple* const _domain_sig;
1605 const TypeTuple* const _domain_cc;
1606 const TypeTuple* const _range; // Range of results
1607
1608 public:
1609 // Constants are shared among ADLC and VM
1610 enum { Control = AdlcVMDeps::Control,
1611 I_O = AdlcVMDeps::I_O,
1612 Memory = AdlcVMDeps::Memory,
1613 FramePtr = AdlcVMDeps::FramePtr,
1614 ReturnAdr = AdlcVMDeps::ReturnAdr,
1615 Parms = AdlcVMDeps::Parms
1616 };
1617
1618
1619 // Accessors:
1620 const TypeTuple* domain_sig() const { return _domain_sig; }
1621 const TypeTuple* domain_cc() const { return _domain_cc; }
1622 const TypeTuple* range() const { return _range; }
1623
1624 static const TypeFunc *make(ciMethod* method);
1625 static const TypeFunc *make(ciSignature signature, const Type* extra);
1626 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* domain_cc, const TypeTuple* range);
1627 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1628
1629 virtual const Type *xmeet( const Type *t ) const;
1630 virtual const Type *xdual() const; // Compute dual right now.
1631
1632 BasicType return_type() const;
1633
1634 #ifndef PRODUCT
1635 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1636 #endif
1637 // Convenience common pre-built types.
1638 };
1639
1640 //------------------------------accessors--------------------------------------
1641 inline bool Type::is_ptr_to_narrowoop() const {
1642 #ifdef _LP64
1643 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1644 #else
1645 return false;
1646 #endif
1647 }
1648
1649 inline bool Type::is_ptr_to_narrowklass() const {
1650 #ifdef _LP64
1651 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1652 #else
|
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_OPTO_TYPE_HPP
26 #define SHARE_VM_OPTO_TYPE_HPP
27
28 #include "ci/ciValueKlass.hpp"
29 #include "opto/adlcVMDeps.hpp"
30 #include "runtime/handles.hpp"
31 #include "runtime/sharedRuntime.hpp"
32
33 // Portions of code courtesy of Clifford Click
34
35 // Optimization - Graph Style
36
37
38 // This class defines a Type lattice. The lattice is used in the constant
39 // propagation algorithms, and for some type-checking of the iloc code.
40 // Basic types include RSD's (lower bound, upper bound, stride for integers),
41 // float & double precision constants, sets of data-labels and code-labels.
42 // The complete lattice is described below. Subtypes have no relationship to
43 // up or down in the lattice; that is entirely determined by the behavior of
44 // the MEET/JOIN functions.
45
46 class Dict;
47 class Type;
48 class TypeD;
49 class TypeF;
50 class TypeInt;
51 class TypeLong;
675 const Type ** const _fields; // Array of field types
676
677 public:
678 virtual bool eq( const Type *t ) const;
679 virtual int hash() const; // Type specific hashing
680 virtual bool singleton(void) const; // TRUE if type is a singleton
681 virtual bool empty(void) const; // TRUE if type is vacuous
682
683 // Accessors:
684 uint cnt() const { return _cnt; }
685 const Type* field_at(uint i) const {
686 assert(i < _cnt, "oob");
687 return _fields[i];
688 }
689 void set_field_at(uint i, const Type* t) {
690 assert(i < _cnt, "oob");
691 _fields[i] = t;
692 }
693
694 static const TypeTuple *make( uint cnt, const Type **fields );
695 static const TypeTuple *make_range(ciSignature *sig, bool ret_vt_fields = false);
696 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, bool vt_fields_as_args = false);
697
698 // Subroutine call type with space allocated for argument types
699 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
700 static const Type **fields( uint arg_cnt );
701
702 virtual const Type *xmeet( const Type *t ) const;
703 virtual const Type *xdual() const; // Compute dual right now.
704 // Convenience common pre-built types.
705 static const TypeTuple *IFBOTH;
706 static const TypeTuple *IFFALSE;
707 static const TypeTuple *IFTRUE;
708 static const TypeTuple *IFNEITHER;
709 static const TypeTuple *LOOPBODY;
710 static const TypeTuple *MEMBAR;
711 static const TypeTuple *STORECONDITIONAL;
712 static const TypeTuple *START_I2C;
713 static const TypeTuple *INT_PAIR;
714 static const TypeTuple *LONG_PAIR;
715 static const TypeTuple *INT_CC_PAIR;
1328 int instance_id = InstanceBot, const TypePtr* speculative = NULL, int inline_depth = InlineDepthBottom);
1329 // Make a pointer to a value type
1330 static const TypeValueTypePtr* make(PTR ptr, ciValueKlass* vk, ciObject* o = NULL) { return make(TypeValueType::make(vk), ptr, o); }
1331 // Make a pointer to a constant value type
1332 static const TypeValueTypePtr* make(ciObject* o) { return make(TypePtr::Constant, o->klass()->as_value_klass(), o); }
1333
1334 const TypeValueType* value_type() const { return _vt; }
1335
1336 virtual const TypePtr* add_offset(intptr_t offset) const;
1337
1338 virtual const Type* cast_to_ptr_type(PTR ptr) const;
1339 virtual const TypeOopPtr* cast_to_instance_id(int instance_id) const;
1340
1341 virtual bool eq(const Type* t) const;
1342 virtual int hash() const; // Type specific hashing
1343 virtual bool empty(void) const; // TRUE if type is vacuous
1344
1345 virtual const Type* xmeet_helper(const Type* t) const;
1346 virtual const Type* xdual() const;
1347
1348 static const TypeValueTypePtr* NOTNULL;
1349
1350 #ifndef PRODUCT
1351 virtual void dump2(Dict &d, uint depth, outputStream* st) const; // Specialized per-Type dumping
1352 #endif
1353 };
1354
1355 //------------------------------TypeMetadataPtr-------------------------------------
1356 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1357 class TypeMetadataPtr : public TypePtr {
1358 protected:
1359 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset);
1360 // Do not allow interface-vs.-noninterface joins to collapse to top.
1361 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1362 public:
1363 virtual bool eq( const Type *t ) const;
1364 virtual int hash() const; // Type specific hashing
1365 virtual bool singleton(void) const; // TRUE if type is a singleton
1366
1367 private:
1368 ciMetadata* _metadata;
1369
1388 static const TypeMetadataPtr *BOTTOM;
1389
1390 #ifndef PRODUCT
1391 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1392 #endif
1393 };
1394
1395 //------------------------------TypeKlassPtr-----------------------------------
1396 // Class of Java Klass pointers
1397 class TypeKlassPtr : public TypePtr {
1398 TypeKlassPtr(PTR ptr, ciKlass* klass, Offset offset);
1399
1400 protected:
1401 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1402 public:
1403 virtual bool eq( const Type *t ) const;
1404 virtual int hash() const; // Type specific hashing
1405 virtual bool singleton(void) const; // TRUE if type is a singleton
1406 private:
1407
1408 ciKlass* _klass;
1409
1410 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1411 bool _klass_is_exact;
1412
1413 public:
1414 ciSymbol* name() const { return klass()->name(); }
1415
1416 ciKlass* klass() const { return _klass; }
1417 bool klass_is_exact() const { return _klass_is_exact; }
1418
1419 bool is_loaded() const { return klass()->is_loaded(); }
1420
1421 // Make a generic (unclassed) pointer to metadata.
1422 static const TypeKlassPtr* make(PTR ptr, Offset offset);
1423
1424 // ptr to klass 'k'
1425 static const TypeKlassPtr* make(ciKlass* k) { return make( TypePtr::Constant, k, Offset(0)); }
1426 // ptr to klass 'k' with offset
1427 static const TypeKlassPtr* make(ciKlass* k, Offset offset) { return make( TypePtr::Constant, k, offset); }
1428 // ptr to klass 'k' or sub-klass
1429 static const TypeKlassPtr* make(PTR ptr, ciKlass* k, Offset offset);
1430
1431 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1432
1433 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1434
1435 // corresponding pointer to instance, for a given class
1436 const TypeOopPtr* as_instance_type() const;
1437
1438 virtual const TypePtr *add_offset( intptr_t offset ) const;
1439 virtual const Type *xmeet( const Type *t ) const;
1440 virtual const Type *xdual() const; // Compute dual right now.
1556 }
1557
1558 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1559 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1560 }
1561
1562 public:
1563 static const TypeNarrowKlass *make( const TypePtr* type);
1564
1565 // static const TypeNarrowKlass *BOTTOM;
1566 static const TypeNarrowKlass *NULL_PTR;
1567
1568 #ifndef PRODUCT
1569 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1570 #endif
1571 };
1572
1573 //------------------------------TypeFunc---------------------------------------
1574 // Class of Array Types
1575 class TypeFunc : public Type {
1576 TypeFunc(const TypeTuple *domain_sig, const TypeTuple *domain_cc, const TypeTuple *range_sig, const TypeTuple *range_cc)
1577 : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range_sig(range_sig), _range_cc(range_cc) {}
1578 virtual bool eq( const Type *t ) const;
1579 virtual int hash() const; // Type specific hashing
1580 virtual bool singleton(void) const; // TRUE if type is a singleton
1581 virtual bool empty(void) const; // TRUE if type is vacuous
1582
1583 // Domains of inputs: value type arguments are not passed by
1584 // reference, instead each field of the value type is passed as an
1585 // argument. We maintain 2 views of the argument list here: one
1586 // based on the signature (with a value type argument as a single
1587 // slot), one based on the actual calling convention (with a value
1588 // type argument as a list of its fields).
1589 const TypeTuple* const _domain_sig;
1590 const TypeTuple* const _domain_cc;
1591 // Range of results. Similar to domains: a value type result can be
1592 // returned in registers in which case range_cc lists all fields and
1593 // is the actual calling convention.
1594 const TypeTuple* const _range_sig;
1595 const TypeTuple* const _range_cc;
1596
1597 public:
1598 // Constants are shared among ADLC and VM
1599 enum { Control = AdlcVMDeps::Control,
1600 I_O = AdlcVMDeps::I_O,
1601 Memory = AdlcVMDeps::Memory,
1602 FramePtr = AdlcVMDeps::FramePtr,
1603 ReturnAdr = AdlcVMDeps::ReturnAdr,
1604 Parms = AdlcVMDeps::Parms
1605 };
1606
1607
1608 // Accessors:
1609 const TypeTuple* domain_sig() const { return _domain_sig; }
1610 const TypeTuple* domain_cc() const { return _domain_cc; }
1611 const TypeTuple* range_sig() const { return _range_sig; }
1612 const TypeTuple* range_cc() const { return _range_cc; }
1613
1614 static const TypeFunc *make(ciMethod* method);
1615 static const TypeFunc *make(ciSignature signature, const Type* extra);
1616 static const TypeFunc *make(const TypeTuple* domain_sig, const TypeTuple* domain_cc,
1617 const TypeTuple* range_sig, const TypeTuple* range_cc);
1618 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1619
1620 virtual const Type *xmeet( const Type *t ) const;
1621 virtual const Type *xdual() const; // Compute dual right now.
1622
1623 BasicType return_type() const;
1624
1625 bool returns_value_type_as_fields() const { return range_sig() != range_cc(); }
1626
1627 #ifndef PRODUCT
1628 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1629 #endif
1630 // Convenience common pre-built types.
1631 };
1632
1633 //------------------------------accessors--------------------------------------
1634 inline bool Type::is_ptr_to_narrowoop() const {
1635 #ifdef _LP64
1636 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1637 #else
1638 return false;
1639 #endif
1640 }
1641
1642 inline bool Type::is_ptr_to_narrowklass() const {
1643 #ifdef _LP64
1644 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1645 #else
|