< prev index next >

src/hotspot/share/runtime/javaCalls.cpp

Print this page




 504     assert(state != value_state_oop, "Multiple handle conversions");
 505     if (is_value_state_indirect_oop(state)) {
 506       oop obj = resolve_indirect_oop(_value[i], state);
 507       _value[i] = cast_from_oop<intptr_t>(obj);
 508       _value_state[i] = value_state_oop;
 509     }
 510   }
 511   // Return argument vector
 512   return _value;
 513 }
 514 
 515 
 516 class SignatureChekker : public SignatureIterator {
 517  private:
 518    int _pos;
 519    BasicType _return_type;
 520    u_char* _value_state;
 521    intptr_t* _value;
 522 
 523  public:
 524   bool _is_return;
 525 
 526   SignatureChekker(Symbol* signature,
 527                    BasicType return_type,
 528                    bool is_static,
 529                    u_char* value_state,
 530                    intptr_t* value) :
 531     SignatureIterator(signature),
 532     _pos(0),
 533     _return_type(return_type),
 534     _value_state(value_state),
 535     _value(value),
 536     _is_return(false)
 537   {
 538     if (!is_static) {
 539       check_value(true); // Receiver must be an oop
 540     }


 541   }
 542 
 543   void check_value(bool type) {

 544     uint state = _value_state[_pos++];
 545     if (type) {
 546       guarantee(is_value_state_indirect_oop(state),
 547                 "signature does not match pushed arguments: %u at %d",
 548                 state, _pos - 1);
 549     } else {
 550       guarantee(state == JavaCallArguments::value_state_primitive,
 551                 "signature does not match pushed arguments: %u at %d",
 552                 state, _pos - 1);
 553     }
 554   }
 555 
 556   void check_doing_return(bool state) { _is_return = state; }
 557 
 558   void check_return_type(BasicType t) {
 559     guarantee(_is_return && t == _return_type, "return type does not match");
 560   }
 561 
 562   void check_int(BasicType t) {
 563     if (_is_return) {
 564       check_return_type(t);
 565       return;
 566     }
 567     check_value(false);
 568   }
 569 
 570   void check_double(BasicType t) { check_long(t); }
 571 
 572   void check_long(BasicType t) {
 573     if (_is_return) {
 574       check_return_type(t);
 575       return;
 576     }
 577 
 578     check_value(false);
 579     check_value(false);
 580   }
 581 
 582   void check_obj(BasicType t) {
 583     if (_is_return) {
 584       check_return_type(t);
 585       return;
 586     }
 587 
 588     intptr_t v = _value[_pos];
 589     if (v != 0) {
 590       // v is a "handle" referring to an oop, cast to integral type.
 591       // There shouldn't be any handles in very low memory.
 592       guarantee((size_t)v >= (size_t)os::vm_page_size(),
 593                 "Bad JNI oop argument %d: " PTR_FORMAT, _pos, v);
 594       // Verify the pointee.
 595       oop vv = resolve_indirect_oop(v, _value_state[_pos]);
 596       guarantee(oopDesc::is_oop_or_null(vv, true),
 597                 "Bad JNI oop argument %d: " PTR_FORMAT " -> " PTR_FORMAT,
 598                 _pos, v, p2i(vv));
 599     }
 600 
 601     check_value(true);          // Verify value state.
 602   }
 603 
 604   void do_bool()                       { check_int(T_BOOLEAN);       }
 605   void do_char()                       { check_int(T_CHAR);          }
 606   void do_float()                      { check_int(T_FLOAT);         }
 607   void do_double()                     { check_double(T_DOUBLE);     }
 608   void do_byte()                       { check_int(T_BYTE);          }
 609   void do_short()                      { check_int(T_SHORT);         }
 610   void do_int()                        { check_int(T_INT);           }
 611   void do_long()                       { check_long(T_LONG);         }
 612   void do_void()                       { check_return_type(T_VOID);  }
 613   void do_object(int begin, int end)   { check_obj(T_OBJECT);        }
 614   void do_array(int begin, int end)    { check_obj(T_OBJECT);        }









 615 };
 616 
 617 
 618 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
 619   guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
 620 
 621   // Treat T_OBJECT and T_ARRAY as the same
 622   if (is_reference_type(return_type)) return_type = T_OBJECT;
 623 
 624   // Check that oop information is correct
 625   Symbol* signature = method->signature();
 626 
 627   SignatureChekker sc(signature,
 628                       return_type,
 629                       method->is_static(),
 630                       _value_state,
 631                       _value);
 632   sc.iterate_parameters();
 633   sc.check_doing_return(true);
 634   sc.iterate_returntype();
 635 }


 504     assert(state != value_state_oop, "Multiple handle conversions");
 505     if (is_value_state_indirect_oop(state)) {
 506       oop obj = resolve_indirect_oop(_value[i], state);
 507       _value[i] = cast_from_oop<intptr_t>(obj);
 508       _value_state[i] = value_state_oop;
 509     }
 510   }
 511   // Return argument vector
 512   return _value;
 513 }
 514 
 515 
 516 class SignatureChekker : public SignatureIterator {
 517  private:
 518    int _pos;
 519    BasicType _return_type;
 520    u_char* _value_state;
 521    intptr_t* _value;
 522 
 523  public:


 524   SignatureChekker(Symbol* signature,
 525                    BasicType return_type,
 526                    bool is_static,
 527                    u_char* value_state,
 528                    intptr_t* value) :
 529     SignatureIterator(signature),
 530     _pos(0),
 531     _return_type(return_type),
 532     _value_state(value_state),
 533     _value(value)

 534   {
 535     if (!is_static) {
 536       check_value(true); // Receiver must be an oop
 537     }
 538     do_parameters_on(this);
 539     check_return_type(return_type);
 540   }
 541 
 542  private:
 543   void check_value(bool is_reference) {
 544     uint state = _value_state[_pos++];
 545     if (is_reference) {
 546       guarantee(is_value_state_indirect_oop(state),
 547                 "signature does not match pushed arguments: %u at %d",
 548                 state, _pos - 1);
 549     } else {
 550       guarantee(state == JavaCallArguments::value_state_primitive,
 551                 "signature does not match pushed arguments: %u at %d",
 552                 state, _pos - 1);
 553     }
 554   }
 555 


 556   void check_return_type(BasicType t) {
 557     guarantee(t == _return_type, "return type does not match");
 558   }
 559 
 560   void check_single_word() {




 561     check_value(false);
 562   }
 563 
 564   void check_double_word() {







 565     check_value(false);
 566     check_value(false);
 567   }
 568 
 569   void check_reference() {





 570     intptr_t v = _value[_pos];
 571     if (v != 0) {
 572       // v is a "handle" referring to an oop, cast to integral type.
 573       // There shouldn't be any handles in very low memory.
 574       guarantee((size_t)v >= (size_t)os::vm_page_size(),
 575                 "Bad JNI oop argument %d: " PTR_FORMAT, _pos, v);
 576       // Verify the pointee.
 577       oop vv = resolve_indirect_oop(v, _value_state[_pos]);
 578       guarantee(oopDesc::is_oop_or_null(vv, true),
 579                 "Bad JNI oop argument %d: " PTR_FORMAT " -> " PTR_FORMAT,
 580                 _pos, v, p2i(vv));
 581     }
 582 
 583     check_value(true);          // Verify value state.
 584   }
 585 
 586   friend class SignatureIterator;  // so do_parameters_on can call do_type
 587   void do_type(BasicType type) {
 588     switch (type) {
 589     case T_BYTE:
 590     case T_BOOLEAN:
 591     case T_CHAR:
 592     case T_SHORT:
 593     case T_INT:
 594     case T_FLOAT:  // this one also
 595       check_single_word(); break;
 596     case T_LONG:
 597     case T_DOUBLE:
 598       check_double_word(); break;
 599     case T_ARRAY:
 600     case T_OBJECT:
 601       check_reference(); break;
 602     default:
 603       ShouldNotReachHere();
 604     }
 605   }
 606 };
 607 
 608 
 609 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
 610   guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
 611 
 612   // Treat T_OBJECT and T_ARRAY as the same
 613   if (is_reference_type(return_type)) return_type = T_OBJECT;
 614 
 615   // Check that oop information is correct
 616   Symbol* signature = method->signature();
 617 
 618   SignatureChekker sc(signature,
 619                       return_type,
 620                       method->is_static(),
 621                       _value_state,
 622                       _value);



 623 }
< prev index next >