1 /* |
1 /* |
2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. 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. |
89 if (VerifyJNIFields && is_checked_jfieldID(id)) { |
89 if (VerifyJNIFields && is_checked_jfieldID(id)) { |
90 result &= small_offset_mask; // cut off the hash bits |
90 result &= small_offset_mask; // cut off the hash bits |
91 } |
91 } |
92 return (intptr_t)result; |
92 return (intptr_t)result; |
93 } |
93 } |
94 static intptr_t encode_klass_hash(klassOop k, intptr_t offset); |
94 static intptr_t encode_klass_hash(Klass* k, intptr_t offset); |
95 static bool klass_hash_ok(klassOop k, jfieldID id); |
95 static bool klass_hash_ok(Klass* k, jfieldID id); |
96 static void verify_instance_jfieldID(klassOop k, jfieldID id); |
96 static void verify_instance_jfieldID(Klass* k, jfieldID id); |
97 |
97 |
98 public: |
98 public: |
99 static bool is_valid_jfieldID(klassOop k, jfieldID id); |
99 static bool is_valid_jfieldID(Klass* k, jfieldID id); |
100 |
100 |
101 static bool is_instance_jfieldID(klassOop k, jfieldID id) { |
101 static bool is_instance_jfieldID(Klass* k, jfieldID id) { |
102 uintptr_t as_uint = (uintptr_t) id; |
102 uintptr_t as_uint = (uintptr_t) id; |
103 return ((as_uint & instance_mask_in_place) != 0); |
103 return ((as_uint & instance_mask_in_place) != 0); |
104 } |
104 } |
105 static bool is_static_jfieldID(jfieldID id) { |
105 static bool is_static_jfieldID(jfieldID id) { |
106 uintptr_t as_uint = (uintptr_t) id; |
106 uintptr_t as_uint = (uintptr_t) id; |
107 return ((as_uint & instance_mask_in_place) == 0); |
107 return ((as_uint & instance_mask_in_place) == 0); |
108 } |
108 } |
109 |
109 |
110 static jfieldID to_instance_jfieldID(klassOop k, int offset) { |
110 static jfieldID to_instance_jfieldID(Klass* k, int offset) { |
111 intptr_t as_uint = ((offset & large_offset_mask) << offset_shift) | instance_mask_in_place; |
111 intptr_t as_uint = ((offset & large_offset_mask) << offset_shift) | instance_mask_in_place; |
112 if (VerifyJNIFields) { |
112 if (VerifyJNIFields) { |
113 as_uint |= encode_klass_hash(k, offset); |
113 as_uint |= encode_klass_hash(k, offset); |
114 } |
114 } |
115 jfieldID result = (jfieldID) as_uint; |
115 jfieldID result = (jfieldID) as_uint; |