Mercurial > hg > truffle
comparison src/share/vm/oops/instanceKlass.cpp @ 676:d3676b4cb78c
Merge
author | kvn |
---|---|
date | Tue, 31 Mar 2009 10:02:01 -0700 |
parents | 4aaa9f5e02a8 c89f86385056 |
children | 6a93908f268f |
comparison
equal
deleted
inserted
replaced
662:9ab385cb0c42 | 676:d3676b4cb78c |
---|---|
1 /* | 1 /* |
2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
1811 // and classname information is enough to determine a class's package | 1811 // and classname information is enough to determine a class's package |
1812 bool instanceKlass::is_same_class_package(oop class_loader1, symbolOop class_name1, | 1812 bool instanceKlass::is_same_class_package(oop class_loader1, symbolOop class_name1, |
1813 oop class_loader2, symbolOop class_name2) { | 1813 oop class_loader2, symbolOop class_name2) { |
1814 if (class_loader1 != class_loader2) { | 1814 if (class_loader1 != class_loader2) { |
1815 return false; | 1815 return false; |
1816 } else if (class_name1 == class_name2) { | |
1817 return true; // skip painful bytewise comparison | |
1816 } else { | 1818 } else { |
1817 ResourceMark rm; | 1819 ResourceMark rm; |
1818 | 1820 |
1819 // The symbolOop's are in UTF8 encoding. Since we only need to check explicitly | 1821 // The symbolOop's are in UTF8 encoding. Since we only need to check explicitly |
1820 // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding. | 1822 // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding. |
1877 // Package-private methods are not inherited outside of package | 1879 // Package-private methods are not inherited outside of package |
1878 assert(super_method->is_package_private(), "must be package private"); | 1880 assert(super_method->is_package_private(), "must be package private"); |
1879 return(is_same_class_package(targetclassloader(), targetclassname())); | 1881 return(is_same_class_package(targetclassloader(), targetclassname())); |
1880 } | 1882 } |
1881 | 1883 |
1884 /* defined for now in jvm.cpp, for historical reasons *-- | |
1885 klassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle self, | |
1886 symbolOop& simple_name_result, TRAPS) { | |
1887 ... | |
1888 } | |
1889 */ | |
1890 | |
1891 // tell if two classes have the same enclosing class (at package level) | |
1892 bool instanceKlass::is_same_package_member_impl(instanceKlassHandle class1, | |
1893 klassOop class2_oop, TRAPS) { | |
1894 if (class2_oop == class1->as_klassOop()) return true; | |
1895 if (!Klass::cast(class2_oop)->oop_is_instance()) return false; | |
1896 instanceKlassHandle class2(THREAD, class2_oop); | |
1897 | |
1898 // must be in same package before we try anything else | |
1899 if (!class1->is_same_class_package(class2->class_loader(), class2->name())) | |
1900 return false; | |
1901 | |
1902 // As long as there is an outer1.getEnclosingClass, | |
1903 // shift the search outward. | |
1904 instanceKlassHandle outer1 = class1; | |
1905 for (;;) { | |
1906 // As we walk along, look for equalities between outer1 and class2. | |
1907 // Eventually, the walks will terminate as outer1 stops | |
1908 // at the top-level class around the original class. | |
1909 symbolOop ignore_name; | |
1910 klassOop next = outer1->compute_enclosing_class(ignore_name, CHECK_false); | |
1911 if (next == NULL) break; | |
1912 if (next == class2()) return true; | |
1913 outer1 = instanceKlassHandle(THREAD, next); | |
1914 } | |
1915 | |
1916 // Now do the same for class2. | |
1917 instanceKlassHandle outer2 = class2; | |
1918 for (;;) { | |
1919 symbolOop ignore_name; | |
1920 klassOop next = outer2->compute_enclosing_class(ignore_name, CHECK_false); | |
1921 if (next == NULL) break; | |
1922 // Might as well check the new outer against all available values. | |
1923 if (next == class1()) return true; | |
1924 if (next == outer1()) return true; | |
1925 outer2 = instanceKlassHandle(THREAD, next); | |
1926 } | |
1927 | |
1928 // If by this point we have not found an equality between the | |
1929 // two classes, we know they are in separate package members. | |
1930 return false; | |
1931 } | |
1932 | |
1933 | |
1882 jint instanceKlass::compute_modifier_flags(TRAPS) const { | 1934 jint instanceKlass::compute_modifier_flags(TRAPS) const { |
1883 klassOop k = as_klassOop(); | 1935 klassOop k = as_klassOop(); |
1884 jint access = access_flags().as_int(); | 1936 jint access = access_flags().as_int(); |
1885 | 1937 |
1886 // But check if it happens to be member class. | 1938 // But check if it happens to be member class. |
2013 // ----------------------------------------------------------------------------------------------------- | 2065 // ----------------------------------------------------------------------------------------------------- |
2014 #ifndef PRODUCT | 2066 #ifndef PRODUCT |
2015 | 2067 |
2016 // Printing | 2068 // Printing |
2017 | 2069 |
2070 #define BULLET " - " | |
2071 | |
2018 void FieldPrinter::do_field(fieldDescriptor* fd) { | 2072 void FieldPrinter::do_field(fieldDescriptor* fd) { |
2019 if (fd->is_static() == (_obj == NULL)) { | 2073 _st->print(BULLET); |
2020 _st->print(" - "); | 2074 if (fd->is_static() || (_obj == NULL)) { |
2021 fd->print_on(_st); | 2075 fd->print_on(_st); |
2022 _st->cr(); | 2076 _st->cr(); |
2023 } else { | 2077 } else { |
2024 fd->print_on_for(_st, _obj); | 2078 fd->print_on_for(_st, _obj); |
2025 _st->cr(); | 2079 _st->cr(); |
2036 juint length = java_lang_String::length(obj); | 2090 juint length = java_lang_String::length(obj); |
2037 if (value != NULL && | 2091 if (value != NULL && |
2038 value->is_typeArray() && | 2092 value->is_typeArray() && |
2039 offset <= (juint) value->length() && | 2093 offset <= (juint) value->length() && |
2040 offset + length <= (juint) value->length()) { | 2094 offset + length <= (juint) value->length()) { |
2041 st->print("string: "); | 2095 st->print(BULLET"string: "); |
2042 Handle h_obj(obj); | 2096 Handle h_obj(obj); |
2043 java_lang_String::print(h_obj, st); | 2097 java_lang_String::print(h_obj, st); |
2044 st->cr(); | 2098 st->cr(); |
2045 if (!WizardMode) return; // that is enough | 2099 if (!WizardMode) return; // that is enough |
2046 } | 2100 } |
2047 } | 2101 } |
2048 | 2102 |
2049 st->print_cr("fields:"); | 2103 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj)); |
2050 FieldPrinter print_nonstatic_field(st, obj); | 2104 FieldPrinter print_nonstatic_field(st, obj); |
2051 do_nonstatic_fields(&print_nonstatic_field); | 2105 do_nonstatic_fields(&print_nonstatic_field); |
2052 | 2106 |
2053 if (as_klassOop() == SystemDictionary::class_klass()) { | 2107 if (as_klassOop() == SystemDictionary::class_klass()) { |
2108 st->print(BULLET"signature: "); | |
2109 java_lang_Class::print_signature(obj, st); | |
2110 st->cr(); | |
2054 klassOop mirrored_klass = java_lang_Class::as_klassOop(obj); | 2111 klassOop mirrored_klass = java_lang_Class::as_klassOop(obj); |
2055 st->print(" - fake entry for mirror: "); | 2112 st->print(BULLET"fake entry for mirror: "); |
2056 mirrored_klass->print_value_on(st); | 2113 mirrored_klass->print_value_on(st); |
2057 st->cr(); | 2114 st->cr(); |
2058 st->print(" - fake entry resolved_constructor: "); | 2115 st->print(BULLET"fake entry resolved_constructor: "); |
2059 methodOop ctor = java_lang_Class::resolved_constructor(obj); | 2116 methodOop ctor = java_lang_Class::resolved_constructor(obj); |
2060 ctor->print_value_on(st); | 2117 ctor->print_value_on(st); |
2061 klassOop array_klass = java_lang_Class::array_klass(obj); | 2118 klassOop array_klass = java_lang_Class::array_klass(obj); |
2062 st->print(" - fake entry for array: "); | 2119 st->cr(); |
2120 st->print(BULLET"fake entry for array: "); | |
2063 array_klass->print_value_on(st); | 2121 array_klass->print_value_on(st); |
2064 st->cr(); | |
2065 st->cr(); | 2122 st->cr(); |
2066 } | 2123 } |
2067 } | 2124 } |
2068 | 2125 |
2069 void instanceKlass::oop_print_value_on(oop obj, outputStream* st) { | 2126 void instanceKlass::oop_print_value_on(oop obj, outputStream* st) { |
2070 st->print("a "); | 2127 st->print("a "); |
2071 name()->print_value_on(st); | 2128 name()->print_value_on(st); |
2072 obj->print_address_on(st); | 2129 obj->print_address_on(st); |
2130 if (as_klassOop() == SystemDictionary::string_klass() | |
2131 && java_lang_String::value(obj) != NULL) { | |
2132 ResourceMark rm; | |
2133 int len = java_lang_String::length(obj); | |
2134 int plen = (len < 24 ? len : 12); | |
2135 char* str = java_lang_String::as_utf8_string(obj, 0, plen); | |
2136 st->print(" = \"%s\"", str); | |
2137 if (len > plen) | |
2138 st->print("...[%d]", len); | |
2139 } else if (as_klassOop() == SystemDictionary::class_klass()) { | |
2140 klassOop k = java_lang_Class::as_klassOop(obj); | |
2141 st->print(" = "); | |
2142 if (k != NULL) { | |
2143 k->print_value_on(st); | |
2144 } else { | |
2145 const char* tname = type2name(java_lang_Class::primitive_type(obj)); | |
2146 st->print("%s", tname ? tname : "type?"); | |
2147 } | |
2148 } else if (java_lang_boxing_object::is_instance(obj)) { | |
2149 st->print(" = "); | |
2150 java_lang_boxing_object::print(obj, st); | |
2151 } | |
2073 } | 2152 } |
2074 | 2153 |
2075 #endif // ndef PRODUCT | 2154 #endif // ndef PRODUCT |
2076 | 2155 |
2077 const char* instanceKlass::internal_name() const { | 2156 const char* instanceKlass::internal_name() const { |