hotspot/test/runtime/StackGuardPages/invoke.c
author stefank
Wed, 20 Apr 2016 09:58:15 +0200
changeset 38000 7519aefb5b86
parent 30290 79e3c82e17aa
child 39390 edf6a424a8b7
permissions -rw-r--r--
8079843: do_young_space_rescan - comment out of sync with code Reviewed-by: mgerdin, sjohanss, ehelin, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24661
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
     1
/*
30290
79e3c82e17aa 8078595: [TESTBUG] Fix runtime/StackGuardPages/testme.sh to deal with 64k pages
goetz
parents: 24661
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
24661
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
     4
 *
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
     7
 * published by the Free Software Foundation.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
     8
 *
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    13
 * accompanied this code).
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    14
 *
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    18
 *
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    21
 * questions.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    22
 *
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    23
 */
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    24
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    25
/* This code tests the fact that we actually remove stack guard page when calling
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    26
 * JavaThread::exit() i.e. when detaching from current thread.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    27
 * We overflow the stack and check that we get access error because of a guard page.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    28
 * Than we detach from vm thread and overflow stack once again. This time we shouldn't
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    29
 * get access error because stack guard page is removed
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    30
 *
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    31
 * Notice: due a complicated interaction of signal handlers, the test may crash.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    32
 * It's OK - don't file a bug.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    33
 */
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    34
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    35
#include <assert.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    36
#include <jni.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    37
#include <alloca.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    38
#include <signal.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    39
#include <sys/mman.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    40
#include <stdlib.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    41
#include <sys/ucontext.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    42
#include <setjmp.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    43
#include <unistd.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    44
#include <sys/syscall.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    45
#include <errno.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    46
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    47
#include <pthread.h>
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    48
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    49
JavaVM* _jvm;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    50
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    51
static jmp_buf  context;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    52
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    53
static int _last_si_code = -1;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    54
static int _failures = 0;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    55
static int _rec_count = 0;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    56
static int _kp_rec_count = 0;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    57
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    58
pid_t gettid() {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    59
  return (pid_t) syscall(SYS_gettid);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    60
}
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    61
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    62
static void handler(int sig, siginfo_t *si, void *unused) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    63
  _last_si_code = si->si_code;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    64
  printf("Got SIGSEGV(%d) at address: 0x%lx\n",si->si_code, (long) si->si_addr);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    65
  longjmp(context, 1);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    66
}
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    67
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    68
void set_signal_handler() {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    69
  static char altstack[SIGSTKSZ];
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    70
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    71
  stack_t ss = {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    72
    .ss_size = SIGSTKSZ,
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    73
    .ss_flags = 0,
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    74
    .ss_sp = altstack
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    75
  };
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    76
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    77
  struct sigaction sa = {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    78
    .sa_sigaction = handler,
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    79
    .sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESETHAND
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    80
  };
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    81
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    82
  _last_si_code = -1;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    83
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    84
  sigaltstack(&ss, 0);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    85
  sigemptyset(&sa.sa_mask);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    86
  if (sigaction(SIGSEGV, &sa, NULL) == -1) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    87
    fprintf(stderr, "Test ERROR. Can't set sigaction (%d)\n", errno);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    88
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    89
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    90
}
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    91
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    92
void *run_java_overflow (void *p) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    93
  JNIEnv *env;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    94
  jclass class_id;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    95
  jmethodID method_id;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    96
  int res;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    97
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    98
  res = (*_jvm)->AttachCurrentThread(_jvm, (void**)&env, NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
    99
  if (res != JNI_OK) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   100
    fprintf(stderr, "Test ERROR. Can't attach to current thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   101
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   102
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   103
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   104
  class_id = (*env)->FindClass (env, "DoOverflow");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   105
  if (class_id == NULL) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   106
    fprintf(stderr, "Test ERROR. Can't load class DoOverflow\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   107
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   108
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   109
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   110
  method_id = (*env)->GetStaticMethodID(env, class_id, "printIt", "()V");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   111
  if (method_id == NULL) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   112
    fprintf(stderr, "Test ERROR. Can't find method DoOverflow.printIt\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   113
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   114
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   115
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   116
  (*env)->CallStaticVoidMethod(env, class_id, method_id, NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   117
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   118
  res = (*_jvm)->DetachCurrentThread(_jvm);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   119
  if (res != JNI_OK) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   120
    fprintf(stderr, "Test ERROR. Can't call detach from current thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   121
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   122
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   123
}
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   124
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   125
void do_overflow(){
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   126
  int *p = alloca(sizeof(int));
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   127
  if (_kp_rec_count == 0 || _rec_count < _kp_rec_count) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   128
      _rec_count ++;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   129
      do_overflow();
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   130
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   131
}
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   132
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   133
void *run_native_overflow(void *p) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   134
  // Test that stack guard page is correctly set for initial and non initial thread
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   135
  // and correctly removed for the initial thread
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   136
  JNIEnv *env;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   137
  jclass class_id;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   138
  jmethodID method_id;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   139
  int res;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   140
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   141
  printf("run_native_overflow %ld\n", (long) gettid());
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   142
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   143
  res = (*_jvm)->AttachCurrentThread(_jvm, (void **)&env, NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   144
  if (res != JNI_OK) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   145
    fprintf(stderr, "Test ERROR. Can't attach to current thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   146
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   147
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   148
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   149
  class_id = (*env)->FindClass (env, "DoOverflow");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   150
  if (class_id == NULL) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   151
    fprintf(stderr, "Test ERROR. Can't load class DoOverflow\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   152
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   153
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   154
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   155
  method_id = (*env)->GetStaticMethodID (env, class_id, "printAlive", "()V");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   156
  if (method_id == NULL) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   157
    fprintf(stderr, "Test ERROR. Can't find method DoOverflow.printAlive\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   158
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   159
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   160
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   161
  (*env)->CallStaticVoidMethod (env, class_id, method_id, NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   162
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   163
  set_signal_handler();
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   164
  if (! setjmp(context)) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   165
    do_overflow();
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   166
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   167
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   168
  if (_last_si_code == SEGV_ACCERR) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   169
    printf("Test PASSED. Got access violation accessing guard page at %d\n", _rec_count);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   170
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   171
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   172
  res = (*_jvm)->DetachCurrentThread(_jvm);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   173
  if (res != JNI_OK) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   174
    fprintf(stderr, "Test ERROR. Can't call detach from current thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   175
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   176
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   177
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   178
  if (getpid() != gettid()) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   179
    // For non-initial thread we don't unmap the region but call os::uncommit_memory and keep PROT_NONE
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   180
    // so if host has enough swap space we will get the same SEGV with code SEGV_ACCERR(2) trying
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   181
    // to access it as if the guard page is present.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   182
    // We have no way to check this, so bail out, marking test as succeeded
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   183
    printf("Test PASSED. Not initial thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   184
    return NULL;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   185
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   186
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   187
  // Limit depth of recursion for second run. It can't exceed one for first run.
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   188
  _kp_rec_count = _rec_count;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   189
  _rec_count = 0;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   190
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   191
  set_signal_handler();
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   192
  if (! setjmp(context)) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   193
    do_overflow();
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   194
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   195
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   196
  if (_last_si_code == SEGV_ACCERR) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   197
      ++ _failures;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   198
      fprintf(stderr,"Test FAILED. Stack guard page is still there at %d\n", _rec_count);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   199
  } else if (_last_si_code == -1) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   200
      printf("Test PASSED. No stack guard page is present. Maximum recursion level reached at %d\n", _rec_count);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   201
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   202
  else{
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   203
      printf("Test PASSED. No stack guard page is present. SIGSEGV(%d) at %d\n", _last_si_code, _rec_count);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   204
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   205
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   206
  return NULL;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   207
}
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   208
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   209
void usage() {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   210
  fprintf(stderr, "Usage: invoke test_java_overflow\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   211
  fprintf(stderr, "       invoke test_native_overflow\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   212
  exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   213
}
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   214
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   215
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   216
int main (int argc, const char** argv) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   217
  JavaVMInitArgs vm_args;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   218
  JavaVMOption options[2];
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   219
  JNIEnv* env;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   220
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   221
  printf("Test started with pid: %ld\n", (long) getpid());
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   222
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   223
  options[0].optionString = "-Xint";
30290
79e3c82e17aa 8078595: [TESTBUG] Fix runtime/StackGuardPages/testme.sh to deal with 64k pages
goetz
parents: 24661
diff changeset
   224
  options[1].optionString = "-Xss328k";
24661
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   225
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   226
  vm_args.version = JNI_VERSION_1_2;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   227
  vm_args.ignoreUnrecognized = JNI_TRUE;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   228
  vm_args.options = options;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   229
  vm_args.nOptions = 2;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   230
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   231
  if (JNI_CreateJavaVM (&_jvm, (void **)&env, &vm_args) < 0 ) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   232
    fprintf(stderr, "Test ERROR. Can't create JavaVM\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   233
    exit(7);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   234
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   235
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   236
  pthread_t thr;
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   237
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   238
  if (argc > 1 && strcmp(argv[1], "test_java_overflow") == 0) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   239
    printf("\nTesting JAVA_OVERFLOW\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   240
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   241
    printf("Testing stack guard page behaviour for other thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   242
    pthread_create (&thr, NULL, run_java_overflow, NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   243
    pthread_join (thr, NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   244
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   245
    printf("Testing stack guard page behaviour for initial thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   246
    run_java_overflow(NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   247
    // This test crash on error
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   248
    exit(0);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   249
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   250
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   251
  if (argc > 1 && strcmp(argv[1], "test_native_overflow") == 0) {
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   252
    printf("\nTesting NATIVE_OVERFLOW\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   253
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   254
    printf("Testing stack guard page behaviour for other thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   255
    pthread_create (&thr, NULL, run_native_overflow, NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   256
    pthread_join (thr, NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   257
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   258
    printf("Testing stack guard page behaviour for initial thread\n");
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   259
    run_native_overflow(NULL);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   260
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   261
    exit((_failures > 0) ? 1 : 0);
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   262
  }
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   263
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   264
  fprintf(stderr, "Test ERROR. Unknown parameter %s\n", ((argc > 1) ? argv[1] : "none"));
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   265
  usage();
27e82ef5a006 8042155: [TESTBUG] Tests for stack guard pages have to be cleaned up
dsamersoff
parents:
diff changeset
   266
}