comparison src/share/vm/oops/instanceKlass.cpp @ 665:c89f86385056

6814659: separable cleanups and subroutines for 6655638 Summary: preparatory but separable changes for method handles Reviewed-by: kvn, never
author jrose
date Fri, 20 Mar 2009 23:19:36 -0700
parents 98cb887364d3
children d3676b4cb78c
comparison
equal deleted inserted replaced
647:bd441136a5ce 665:c89f86385056
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.
1857 return UTF8::equal(name1, length1, name2, length2); 1859 return UTF8::equal(name1, length1, name2, length2);
1858 } 1860 }
1859 } 1861 }
1860 } 1862 }
1861 1863
1864 /* defined for now in jvm.cpp, for historical reasons *--
1865 klassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle self,
1866 symbolOop& simple_name_result, TRAPS) {
1867 ...
1868 }
1869 */
1870
1871 // tell if two classes have the same enclosing class (at package level)
1872 bool instanceKlass::is_same_package_member_impl(instanceKlassHandle class1,
1873 klassOop class2_oop, TRAPS) {
1874 if (class2_oop == class1->as_klassOop()) return true;
1875 if (!Klass::cast(class2_oop)->oop_is_instance()) return false;
1876 instanceKlassHandle class2(THREAD, class2_oop);
1877
1878 // must be in same package before we try anything else
1879 if (!class1->is_same_class_package(class2->class_loader(), class2->name()))
1880 return false;
1881
1882 // As long as there is an outer1.getEnclosingClass,
1883 // shift the search outward.
1884 instanceKlassHandle outer1 = class1;
1885 for (;;) {
1886 // As we walk along, look for equalities between outer1 and class2.
1887 // Eventually, the walks will terminate as outer1 stops
1888 // at the top-level class around the original class.
1889 symbolOop ignore_name;
1890 klassOop next = outer1->compute_enclosing_class(ignore_name, CHECK_false);
1891 if (next == NULL) break;
1892 if (next == class2()) return true;
1893 outer1 = instanceKlassHandle(THREAD, next);
1894 }
1895
1896 // Now do the same for class2.
1897 instanceKlassHandle outer2 = class2;
1898 for (;;) {
1899 symbolOop ignore_name;
1900 klassOop next = outer2->compute_enclosing_class(ignore_name, CHECK_false);
1901 if (next == NULL) break;
1902 // Might as well check the new outer against all available values.
1903 if (next == class1()) return true;
1904 if (next == outer1()) return true;
1905 outer2 = instanceKlassHandle(THREAD, next);
1906 }
1907
1908 // If by this point we have not found an equality between the
1909 // two classes, we know they are in separate package members.
1910 return false;
1911 }
1912
1862 1913
1863 jint instanceKlass::compute_modifier_flags(TRAPS) const { 1914 jint instanceKlass::compute_modifier_flags(TRAPS) const {
1864 klassOop k = as_klassOop(); 1915 klassOop k = as_klassOop();
1865 jint access = access_flags().as_int(); 1916 jint access = access_flags().as_int();
1866 1917
1994 // ----------------------------------------------------------------------------------------------------- 2045 // -----------------------------------------------------------------------------------------------------
1995 #ifndef PRODUCT 2046 #ifndef PRODUCT
1996 2047
1997 // Printing 2048 // Printing
1998 2049
2050 #define BULLET " - "
2051
1999 void FieldPrinter::do_field(fieldDescriptor* fd) { 2052 void FieldPrinter::do_field(fieldDescriptor* fd) {
2000 if (fd->is_static() == (_obj == NULL)) { 2053 _st->print(BULLET);
2001 _st->print(" - "); 2054 if (fd->is_static() || (_obj == NULL)) {
2002 fd->print_on(_st); 2055 fd->print_on(_st);
2003 _st->cr(); 2056 _st->cr();
2004 } else { 2057 } else {
2005 fd->print_on_for(_st, _obj); 2058 fd->print_on_for(_st, _obj);
2006 _st->cr(); 2059 _st->cr();
2017 juint length = java_lang_String::length(obj); 2070 juint length = java_lang_String::length(obj);
2018 if (value != NULL && 2071 if (value != NULL &&
2019 value->is_typeArray() && 2072 value->is_typeArray() &&
2020 offset <= (juint) value->length() && 2073 offset <= (juint) value->length() &&
2021 offset + length <= (juint) value->length()) { 2074 offset + length <= (juint) value->length()) {
2022 st->print("string: "); 2075 st->print(BULLET"string: ");
2023 Handle h_obj(obj); 2076 Handle h_obj(obj);
2024 java_lang_String::print(h_obj, st); 2077 java_lang_String::print(h_obj, st);
2025 st->cr(); 2078 st->cr();
2026 if (!WizardMode) return; // that is enough 2079 if (!WizardMode) return; // that is enough
2027 } 2080 }
2028 } 2081 }
2029 2082
2030 st->print_cr("fields:"); 2083 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj));
2031 FieldPrinter print_nonstatic_field(st, obj); 2084 FieldPrinter print_nonstatic_field(st, obj);
2032 do_nonstatic_fields(&print_nonstatic_field); 2085 do_nonstatic_fields(&print_nonstatic_field);
2033 2086
2034 if (as_klassOop() == SystemDictionary::class_klass()) { 2087 if (as_klassOop() == SystemDictionary::class_klass()) {
2088 st->print(BULLET"signature: ");
2089 java_lang_Class::print_signature(obj, st);
2090 st->cr();
2035 klassOop mirrored_klass = java_lang_Class::as_klassOop(obj); 2091 klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
2036 st->print(" - fake entry for mirror: "); 2092 st->print(BULLET"fake entry for mirror: ");
2037 mirrored_klass->print_value_on(st); 2093 mirrored_klass->print_value_on(st);
2038 st->cr(); 2094 st->cr();
2039 st->print(" - fake entry resolved_constructor: "); 2095 st->print(BULLET"fake entry resolved_constructor: ");
2040 methodOop ctor = java_lang_Class::resolved_constructor(obj); 2096 methodOop ctor = java_lang_Class::resolved_constructor(obj);
2041 ctor->print_value_on(st); 2097 ctor->print_value_on(st);
2042 klassOop array_klass = java_lang_Class::array_klass(obj); 2098 klassOop array_klass = java_lang_Class::array_klass(obj);
2043 st->print(" - fake entry for array: "); 2099 st->cr();
2100 st->print(BULLET"fake entry for array: ");
2044 array_klass->print_value_on(st); 2101 array_klass->print_value_on(st);
2045 st->cr();
2046 st->cr(); 2102 st->cr();
2047 } 2103 }
2048 } 2104 }
2049 2105
2050 void instanceKlass::oop_print_value_on(oop obj, outputStream* st) { 2106 void instanceKlass::oop_print_value_on(oop obj, outputStream* st) {
2051 st->print("a "); 2107 st->print("a ");
2052 name()->print_value_on(st); 2108 name()->print_value_on(st);
2053 obj->print_address_on(st); 2109 obj->print_address_on(st);
2110 if (as_klassOop() == SystemDictionary::string_klass()
2111 && java_lang_String::value(obj) != NULL) {
2112 ResourceMark rm;
2113 int len = java_lang_String::length(obj);
2114 int plen = (len < 24 ? len : 12);
2115 char* str = java_lang_String::as_utf8_string(obj, 0, plen);
2116 st->print(" = \"%s\"", str);
2117 if (len > plen)
2118 st->print("...[%d]", len);
2119 } else if (as_klassOop() == SystemDictionary::class_klass()) {
2120 klassOop k = java_lang_Class::as_klassOop(obj);
2121 st->print(" = ");
2122 if (k != NULL) {
2123 k->print_value_on(st);
2124 } else {
2125 const char* tname = type2name(java_lang_Class::primitive_type(obj));
2126 st->print("%s", tname ? tname : "type?");
2127 }
2128 } else if (java_lang_boxing_object::is_instance(obj)) {
2129 st->print(" = ");
2130 java_lang_boxing_object::print(obj, st);
2131 }
2054 } 2132 }
2055 2133
2056 #endif // ndef PRODUCT 2134 #endif // ndef PRODUCT
2057 2135
2058 const char* instanceKlass::internal_name() const { 2136 const char* instanceKlass::internal_name() const {