8216010: Change callers of build_u2_from() to call Bytes::get_Java_u2() instead
authorhseigel
Fri, 04 Jan 2019 14:28:27 -0500
changeset 53147 db1d11c253d8
parent 53146 62a4355dc9c8
child 53148 17d568776429
8216010: Change callers of build_u2_from() to call Bytes::get_Java_u2() instead Summary: Change the callers and delete function build_u2_from() Reviewed-by: kbarrett, jiangli, coleenp
src/hotspot/share/aot/aotCodeHeap.cpp
src/hotspot/share/aot/aotCompiledMethod.cpp
src/hotspot/share/jvmci/compilerRuntime.cpp
src/hotspot/share/utilities/globalDefinitions.hpp
--- a/src/hotspot/share/aot/aotCodeHeap.cpp	Fri Jan 04 10:42:12 2019 -0800
+++ b/src/hotspot/share/aot/aotCodeHeap.cpp	Fri Jan 04 14:28:27 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,7 @@
 #include "runtime/safepointVerifiers.hpp"
 #include "runtime/sharedRuntime.hpp"
 #include "runtime/vmOperations.hpp"
+#include "utilities/sizes.hpp"
 
 bool AOTLib::_narrow_oop_shift_initialized = false;
 int  AOTLib::_narrow_oop_shift = 0;
@@ -395,7 +396,7 @@
     int code_id = stub_offsets[i]._code_id;
     assert(code_id < _method_count, "sanity");
     jlong* state_adr = &_method_state[code_id];
-    int len = build_u2_from((address)stub_name);
+    int len = Bytes::get_Java_u2((address)stub_name);
     stub_name += 2;
     char* full_name = NEW_C_HEAP_ARRAY(char, len+5, mtCode);
     if (full_name == NULL) { // No memory?
@@ -606,10 +607,10 @@
 #endif
 
 Method* AOTCodeHeap::find_method(Klass* klass, Thread* thread, const char* method_name) {
-  int method_name_len = build_u2_from((address)method_name);
+  int method_name_len = Bytes::get_Java_u2((address)method_name);
   method_name += 2;
   const char* signature_name = method_name + method_name_len;
-  int signature_name_len = build_u2_from((address)signature_name);
+  int signature_name_len = Bytes::get_Java_u2((address)signature_name);
   signature_name += 2;
   // The class should have been loaded so the method and signature should already be
   // in the symbol table.  If they're not there, the method doesn't exist.
@@ -821,7 +822,7 @@
       method_data->_metadata_table = (address)_metadata_got + method_offsets->_metadata_got_offset;
       method_data->_metadata_size  = method_offsets->_metadata_got_size;
       // aot_name format: "<u2_size>Ljava/lang/ThreadGroup;<u2_size>addUnstarted<u2_size>()V"
-      int klass_len = build_u2_from((address)aot_name);
+      int klass_len = Bytes::get_Java_u2((address)aot_name);
       const char* method_name = aot_name + 2 + klass_len;
       Method* m = AOTCodeHeap::find_method(ik, thread, method_name);
       methodHandle mh(thread, m);
--- a/src/hotspot/share/aot/aotCompiledMethod.cpp	Fri Jan 04 10:42:12 2019 -0800
+++ b/src/hotspot/share/aot/aotCompiledMethod.cpp	Fri Jan 04 14:28:27 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,7 @@
 #include "runtime/os.hpp"
 #include "runtime/safepointVerifiers.hpp"
 #include "runtime/sharedRuntime.hpp"
+#include "utilities/sizes.hpp"
 #include "utilities/xmlstream.hpp"
 
 #include <stdio.h>
@@ -88,7 +89,7 @@
   }
   // The entry is string which we need to resolve.
   const char* meta_name = _heap->get_name_at((int)meta);
-  int klass_len = build_u2_from((address)meta_name);
+  int klass_len = Bytes::get_Java_u2((address)meta_name);
   const char* klass_name = meta_name + 2;
   // Quick check the current method's holder.
   Klass* k = _method->method_holder();
@@ -98,7 +99,7 @@
     // Search klass in got cells in DSO which have this compiled method.
     k = _heap->get_klass_from_got(klass_name, klass_len, _method);
   }
-  int method_name_len = build_u2_from((address)klass_name + klass_len);
+  int method_name_len = Bytes::get_Java_u2((address)klass_name + klass_len);
   guarantee(method_name_len == 0, "only klass is expected here");
   meta = ((intptr_t)k) | 1;
   *entry = (Metadata*)meta; // Should be atomic on x64
@@ -120,7 +121,7 @@
     }
     // The entry is string which we need to resolve.
     const char* meta_name = _heap->get_name_at((int)meta);
-    int klass_len = build_u2_from((address)meta_name);
+    int klass_len = Bytes::get_Java_u2((address)meta_name);
     const char* klass_name = meta_name + 2;
     // Quick check the current method's holder.
     Klass* k = _method->method_holder();
@@ -132,7 +133,7 @@
       k = _heap->get_klass_from_got(klass_name, klass_len, _method);
       klass_matched = false;
     }
-    int method_name_len = build_u2_from((address)klass_name + klass_len);
+    int method_name_len = Bytes::get_Java_u2((address)klass_name + klass_len);
     if (method_name_len == 0) { // Array or Klass name only?
       meta = ((intptr_t)k) | 1;
       *entry = (Metadata*)meta; // Should be atomic on x64
@@ -140,7 +141,7 @@
     } else { // Method
       // Quick check the current method's name.
       Method* m = _method;
-      int signature_len = build_u2_from((address)klass_name + klass_len + 2 + method_name_len);
+      int signature_len = Bytes::get_Java_u2((address)klass_name + klass_len + 2 + method_name_len);
       int full_len = 2 + klass_len + 2 + method_name_len + 2 + signature_len;
       if (!klass_matched || memcmp(_name, meta_name, full_len) != 0) { // Does not match?
         Thread* thread = Thread::current();
--- a/src/hotspot/share/jvmci/compilerRuntime.cpp	Fri Jan 04 10:42:12 2019 -0800
+++ b/src/hotspot/share/jvmci/compilerRuntime.cpp	Fri Jan 04 14:28:27 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@
 #include "runtime/deoptimization.hpp"
 #include "runtime/interfaceSupport.inline.hpp"
 #include "runtime/vframe.inline.hpp"
+#include "utilities/sizes.hpp"
 #include "aot/aotLoader.hpp"
 
 // Resolve and allocate String
@@ -41,7 +42,7 @@
     oop str = *(oop*)string_result; // Is it resolved already?
     if (str == NULL) { // Do resolution
       // First 2 bytes of name contains length (number of bytes).
-      int len = build_u2_from((address)name);
+      int len = Bytes::get_Java_u2((address)name);
       name += 2;
       TempNewSymbol sym = SymbolTable::new_symbol(name, len, CHECK);
       str = StringTable::intern(sym, CHECK);
@@ -92,7 +93,7 @@
     k = *klass_result; // Is it resolved already?
     if (k == NULL) { // Do resolution
       // First 2 bytes of name contains length (number of bytes).
-      int len = build_u2_from((address)name);
+      int len = Bytes::get_Java_u2((address)name);
       name += 2;
       k = CompilerRuntime::resolve_klass_helper(thread, name, len, CHECK_NULL);
       *klass_result = k; // Store result
@@ -186,13 +187,13 @@
   JRT_BLOCK
      if (c == NULL) { // Do resolution
        // Get method name and its length
-       int method_name_len = build_u2_from((address)data);
+       int method_name_len = Bytes::get_Java_u2((address)data);
        data += sizeof(u2);
        const char* method_name = data;
        data += method_name_len;
 
        // Get signature and its length
-       int signature_name_len = build_u2_from((address)data);
+       int signature_name_len = Bytes::get_Java_u2((address)data);
        data += sizeof(u2);
        const char* signature_name = data;
 
@@ -221,7 +222,7 @@
       k = klass_result[1]; // Is it resolved already?
       if (k == NULL) { // Do resolution
         // First 2 bytes of name contains length (number of bytes).
-        int len = build_u2_from((address)name);
+        int len = Bytes::get_Java_u2((address)name);
         const char *cname = name + 2;
         k = CompilerRuntime::resolve_klass_helper(thread,  cname, len, CHECK_NULL);
         klass_result[1] = k; // Store resolved result
--- a/src/hotspot/share/utilities/globalDefinitions.hpp	Fri Jan 04 10:42:12 2019 -0800
+++ b/src/hotspot/share/utilities/globalDefinitions.hpp	Fri Jan 04 14:28:27 2019 -0500
@@ -1094,21 +1094,6 @@
   return (address)to - (address)from;
 }
 
-//----------------------------------------------------------------------------------------------------
-// Avoid non-portable casts with these routines (DEPRECATED)
-
-// NOTE: USE Bytes class INSTEAD WHERE POSSIBLE
-//       Bytes is optimized machine-specifically and may be much faster than the portable routines below.
-
-// Given sequence of four bytes, build into a 32-bit word
-// following the conventions used in class files.
-
-// This one works if the two bytes are contiguous in memory:
-inline u2 build_u2_from( u1* p ) {
-  return  u2((( u2(p[0]) <<  8 )  &  0xff00)
-          |  (( u2(p[1]) <<  0 )  &  0x00ff));
-}
-
 
 // Pack and extract shorts to/from ints: