src/hotspot/os/aix/safepointMechanism_aix.cpp
author mdoerr
Tue, 14 Nov 2017 16:45:27 +0100
changeset 47889 839a3b403a5e
parent 47881 0ce0ac68ace7
child 48506 478e77658965
permissions -rw-r--r--
8191212: AIX: Build and polling page allocation broken after 8189941 Reviewed-by: stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     1
/*
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     4
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     8
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    13
 * accompanied this code).
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    14
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    18
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    21
 * questions.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    22
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    23
 */
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    24
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    25
#include "precompiled.hpp"
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    26
#include "logging/log.hpp"
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    27
#include "runtime/globals.hpp"
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    28
#include "runtime/os.hpp"
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    29
#include "runtime/safepointMechanism.hpp"
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    30
#include <sys/mman.h>
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    31
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    32
void SafepointMechanism::pd_initialize() {
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    33
  char* map_address = (char*)MAP_FAILED;
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    34
  const size_t page_size = os::vm_page_size();
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    35
  // Use optimized addresses for the polling page,
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    36
  // e.g. map it to a special 32-bit address.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    37
  if (OptimizePollingPageLocation) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    38
    // architecture-specific list of address wishes:
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    39
    char* address_wishes[] = {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    40
        // AIX: addresses lower than 0x30000000 don't seem to work on AIX.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    41
        // PPC64: all address wishes are non-negative 32 bit values where
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    42
        // the lower 16 bits are all zero. we can load these addresses
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    43
        // with a single ppc_lis instruction.
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    44
        (char*) 0x30000000, (char*) 0x31000000,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    45
        (char*) 0x32000000, (char*) 0x33000000,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    46
        (char*) 0x40000000, (char*) 0x41000000,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    47
        (char*) 0x42000000, (char*) 0x43000000,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    48
        (char*) 0x50000000, (char*) 0x51000000,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    49
        (char*) 0x52000000, (char*) 0x53000000,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    50
        (char*) 0x60000000, (char*) 0x61000000,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    51
        (char*) 0x62000000, (char*) 0x63000000
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    52
    };
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    53
    int address_wishes_length = sizeof(address_wishes)/sizeof(char*);
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    54
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    55
    // iterate over the list of address wishes:
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    56
    for (int i = 0; i < address_wishes_length; i++) {
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    57
      // Try to map with current address wish.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    58
      // AIX: AIX needs MAP_FIXED if we provide an address and mmap will
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    59
      // fail if the address is already mapped.
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    60
      map_address = (char*) ::mmap(address_wishes[i] - (ssize_t)page_size,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    61
                                   page_size, PROT_READ,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    62
                                   MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    63
                                   -1, 0);
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    64
      log_debug(os)("SafePoint Polling  Page address: %p (wish) => %p",
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    65
                    address_wishes[i], map_address + (ssize_t)page_size);
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    66
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    67
      if (map_address + (ssize_t)page_size == address_wishes[i]) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    68
        // Map succeeded and map_address is at wished address, exit loop.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    69
        break;
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    70
      }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    71
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    72
      if (map_address != (char*)MAP_FAILED) {
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    73
        // Map succeeded, but polling_page is not at wished address, unmap and continue.
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    74
        ::munmap(map_address, page_size);
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    75
        map_address = (char*)MAP_FAILED;
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    76
      }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    77
      // Map failed, continue loop.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    78
    }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    79
  }
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    80
  if (map_address == (char*)MAP_FAILED) {
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    81
    map_address = os::reserve_memory(page_size, NULL, page_size);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    82
  }
47889
839a3b403a5e 8191212: AIX: Build and polling page allocation broken after 8189941
mdoerr
parents: 47881
diff changeset
    83
  guarantee(map_address != (char*)MAP_FAILED, "SafepointMechanism::pd_initialize: failed to allocate polling page");
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    84
  os::set_polling_page((address)(map_address));
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    85
}