Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #include "src/globals.h" |
| 4 | #include "src/object.h" |
| 5 | #include "src/logging.h" |
| 6 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame^] | 7 | #include <string.h> |
| 8 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 9 | namespace art { |
| 10 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame^] | 11 | bool Class::IsInSamePackage(const char* descriptor1, const char* descriptor2) { |
| 12 | size_t i = 0; |
| 13 | while (descriptor1[i] != '\0' && descriptor1[i] == descriptor2[i]) { |
| 14 | ++i; |
| 15 | } |
| 16 | if (strrchr(descriptor1 + i, '/') != NULL || |
| 17 | strrchr(descriptor2 + i, '/') != NULL ) { |
| 18 | return false; |
| 19 | } else { |
| 20 | return true; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | bool Class::IsInSamePackage(const Class* that) const { |
| 25 | const Class* klass1 = this; |
| 26 | const Class* klass2 = that; |
| 27 | if (klass1 == klass2) { |
| 28 | return true; |
| 29 | } |
| 30 | // Class loaders must match. |
| 31 | if (klass1->class_loader_ != klass2->class_loader_) { |
| 32 | return false; |
| 33 | } |
| 34 | // Arrays are in the same package when their element classes are. |
| 35 | if (klass1->IsArray()) { |
| 36 | klass1 = klass1->array_element_class_; |
| 37 | } |
| 38 | if (klass2->IsArray()) { |
| 39 | klass2 = klass2->array_element_class_; |
| 40 | } |
| 41 | // Compare the package part of the descriptor string. |
| 42 | return IsInSamePackage(klass1->descriptor_, klass2->descriptor_); |
| 43 | } |
| 44 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 45 | uint32_t Method::NumArgRegisters() { |
| 46 | CHECK(shorty_ != NULL); |
| 47 | uint32_t num_registers = 0; |
| 48 | for (size_t i = 1; shorty_[0] != '\0'; ++i) { |
| 49 | char ch = shorty_[i]; |
| 50 | if (ch == 'D' || ch == 'J') { |
| 51 | num_registers += 2; |
| 52 | } else { |
| 53 | num_registers += 1; |
| 54 | } |
| 55 | } |
| 56 | return num_registers; |
| 57 | } |
| 58 | |
| 59 | } // namespace art |