1 /*
  2  * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2016, 2017 SAP SE. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef CPU_S390_STUBROUTINES_S390_HPP
 27 #define CPU_S390_STUBROUTINES_S390_HPP
 28 
 29 // This file holds the platform specific parts of the StubRoutines
 30 // definition. See stubRoutines.hpp for a description on how to extend it.
 31 
 32 static bool returns_to_call_stub(address return_pc) { return return_pc == _call_stub_return_address; }
 33 
 34 // emit enum used to size per-blob code buffers
 35 
 36 #define DEFINE_BLOB_SIZE(blob_name, size) \
 37   _ ## blob_name ## _code_size = size,
 38 
 39 enum platform_dependent_constants {
 40   STUBGEN_ARCH_BLOBS_DO(DEFINE_BLOB_SIZE)
 41 };
 42 
 43 #undef DEFINE_BLOB_SIZE
 44 
 45 // MethodHandles adapters
 46 enum method_handles_platform_dependent_constants {
 47   method_handles_adapters_code_size = 5000
 48 };
 49 
 50 #define CRC32_COLUMN_SIZE 256
 51 #define CRC32_BYFOUR
 52 #ifdef CRC32_BYFOUR
 53   #define CRC32_TABLES 8
 54 #else
 55   #define CRC32_TABLES 1
 56 #endif
 57 
 58 // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
 59 #define TROT_ALIGNMENT   8  // Required by instruction,
 60                             // guaranteed by jlong table element type.
 61 #define TROT_COLUMN_SIZE (256*sizeof(jchar)/sizeof(jlong))
 62 
 63 class zarch {
 64  friend class StubGenerator;
 65  friend class StubRoutines;
 66 
 67  public:
 68   enum { nof_instance_allocators = 10 };
 69 
 70   // allocator lock values
 71   enum {
 72     unlocked = 0,
 73     locked   = 1
 74   };
 75 
 76   // declare fields for arch-specific entries
 77 
 78 #define DECLARE_ARCH_ENTRY(arch, blob_name, stub_name, field_name, getter_name) \
 79   static address STUB_FIELD_NAME(field_name) ;
 80 
 81 #define DECLARE_ARCH_ENTRY_INIT(arch, blob_name, stub_name, field_name, getter_name, init_function) \
 82   DECLARE_ARCH_ENTRY(arch, blob_name, stub_name, field_name, getter_name)
 83 
 84 private:
 85   STUBGEN_ARCH_ENTRIES_DO(DECLARE_ARCH_ENTRY, DECLARE_ARCH_ENTRY_INIT)
 86 
 87 #undef DECLARE_ARCH_ENTRY_INIT
 88 #undef DECLARE_ARCH_ENTRY
 89 
 90  private:
 91 
 92   static int _atomic_memory_operation_lock;
 93 
 94   static juint   _crc_table[CRC32_TABLES][CRC32_COLUMN_SIZE];
 95   static juint   _crc32c_table[CRC32_TABLES][CRC32_COLUMN_SIZE];
 96 
 97   // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
 98   static address _trot_table_addr;
 99   static jlong   _trot_table[TROT_COLUMN_SIZE];
100 
101  public:
102 
103   // declare getters for arch-specific entries
104 
105 #define DEFINE_ARCH_ENTRY_GETTER(arch, blob_name, stub_name, field_name, getter_name) \
106   static address getter_name() { return STUB_FIELD_NAME(field_name) ; }
107 
108 #define DEFINE_ARCH_ENTRY_GETTER_INIT(arch, blob_name, stub_name, field_name, getter_name, init_function) \
109   DEFINE_ARCH_ENTRY_GETTER(arch, blob_name, stub_name, field_name, getter_name)
110 
111   STUBGEN_ARCH_ENTRIES_DO(DEFINE_ARCH_ENTRY_GETTER, DEFINE_ARCH_ENTRY_GETTER_INIT)
112 
113 #undef DEFINE_ARCH_ENTRY_GETTER_INIT
114 #undef DEFINE_ARCH_ENTRY_GETTER
115 
116   // Global lock for everyone who needs to use atomic_compare_and_exchange
117   // or atomic_increment -- should probably use more locks for more
118   // scalability -- for instance one for each eden space or group of.
119 
120   // Address of the lock for atomic_compare_and_exchange.
121   static int* atomic_memory_operation_lock_addr() { return &_atomic_memory_operation_lock; }
122 
123   // Accessor and mutator for _atomic_memory_operation_lock.
124   static int atomic_memory_operation_lock() { return _atomic_memory_operation_lock; }
125   static void set_atomic_memory_operation_lock(int value) { _atomic_memory_operation_lock = value; }
126 
127   static void generate_load_absolute_address(MacroAssembler* masm, Register table, address table_addr, uint64_t table_contents);
128   static void generate_load_crc_table_addr(MacroAssembler* masm, Register table);
129   static void generate_load_crc32c_table_addr(MacroAssembler* masm, Register table);
130 
131   // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
132   static void generate_load_trot_table_addr(MacroAssembler* masm, Register table);
133 };
134 
135 #endif // CPU_S390_STUBROUTINES_S390_HPP