需要解释为什么会发生 EXCEPTION_ACCESS_VIOLATION [英] need explanation on why does EXCEPTION_ACCESS_VIOLATION occur

查看:38
本文介绍了需要解释为什么会发生 EXCEPTION_ACCESS_VIOLATION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我要显示的这个错误无法通过代码修复.我只想知道这是为什么以及如何引起的,我也知道这是由于 JVM 试图访问另一个程序的地址空间.

 Java 运行时环境检测到一个致命错误:EXCEPTION_ACCESS_VIOLATION (0xc0000005) 在 pc=0x6dcd422a,pid=4024,tid=3900JRE 版本:6.0_14-b08Java VM:Java HotSpot(TM) 服务器 VM(14.0-b16 混合模式 windows-x86)有问题的框架:V [jvm.dll+0x17422a]包含更多信息的错误报告文件保存为:C:PServerserverinhs_err_pid4024.log如果您想提交错误报告,请访问:http://java.sun.com/webapps/bugreport/crash.jsp

解决方案

来自 Tanenbaum 的现代操作系统"一书,可在此处在线获取:

http://lovingod.host.sk/tanenbaum/Unix-Linux-Windows.html

深入介绍主题.(第 4 章是内存管理,第 4.8 章是内存分段).简短版本:

如果您 PC 上的多个程序可以访问彼此的内存,那将是非常糟糕的.实际上,即使在一个程序中,即使在一个线程中,您也有多个不得相互影响的内存区域.通常一个进程至少有一个称为堆栈"的内存区域和一个称为堆"的区域(通常每个进程有一个堆+每个线程一个堆栈.可能有更多的段,但这取决于实现,它不会这里的解释很重要).在堆栈中保存了函数参数和局部变量之类的东西.在堆上是保存的变量,其大小和生存期无法由编译器在编译时确定(在 Java 中,您使用new"-Operator 的所有内容都将如此.示例:

public void bar(String  int myInt){String foo = new String("foobar");}

在这个例子中是两个 String 对象:(由foo"和hi"引用).这两个对象都在堆上(你知道这一点,因为在某些时候,两个字符串都是使用new"分配的.在这个例子中,堆栈上有 3 个值.这将是myInt"、hi"和"foo".重要的是要意识到 "hi" 和 "foo" 并没有真正直接包含字符串,而是它们包含一些 id,告诉它们在堆上可以找到字符串.(这并不容易用java解释一下,因为java抽象了很多.在C中,hi"和foo"将是一个指针,它实际上只是一个整数,表示存储实际值的堆中的地址).

你可能会问自己为什么会有一个栈和一个堆.为什么不把所有东西都放在同一个地方.不幸的是,解释超出了这个答案的范围.阅读我链接的书;-).简短的版本是堆栈和堆的管理不同,并且出于优化的原因进行了分离.

栈和堆的大小是有限的.(在 Linux 上执行 ulimit -a,你会得到一个列表,包括数据段大小"(堆)和堆栈大小"(是的...堆栈 :-)).>

堆栈是不断增长的东西.就像一个数组,如果你添加越来越多的数据,它就会变得越来越大.最终你的空间用完了.在这种情况下,您可能最终会写入不再属于您的内存区域.那将是非常糟糕的.因此,操作系统会注意到这一点并在发生这种情况时停止该程序.在 Linux 上,您会收到分段错误",而在 Windows 上,您会收到访问冲突".

在 C 等其他语言中,您需要手动管理内存.一个微小的错误很容易导致您不小心写入一些不属于您的空间.在 Java 中,您有自动内存管理",这意味着 JVM 会为您完成所有这些工作.你不需要关心,作为开发人员,这会减轻你的负担(通常是这样.我敢打赌,有些人会不同意负载"部分;-)).这意味着它/应该/不可能产生与 java 的分段错误.不幸的是,JVM 并不完美.有时它有错误和搞砸.然后你就会得到你所得到的.

Hi I know that this error which I'm going to show can't be fixed through code. I just want to know why and how is it caused and I also know its due to JVM trying to access address space of another program.

 A fatal error has been detected by the Java Runtime Environment:

  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6dcd422a, pid=4024, tid=3900

 JRE version: 6.0_14-b08
 Java VM: Java HotSpot(TM) Server VM (14.0-b16 mixed mode windows-x86 )
 Problematic frame:
 V  [jvm.dll+0x17422a]

An error report file with more information is saved as:
C:PServerserverinhs_err_pid4024.log

If you would like to submit a bug report, please visit:
http://java.sun.com/webapps/bugreport/crash.jsp

解决方案

The book "modern operating systems" from Tanenbaum, which is available online here:

http://lovingod.host.sk/tanenbaum/Unix-Linux-Windows.html

Covers the topic in depth. (Chapter 4 is in Memory Management and Chapter 4.8 is on Memory segmentation). The short version:

It would be very bad if several programs on your PC could access each other's memory. Actually even within one program, even in one thread you have multiple areas of memory that must not influence one other. Usually a process has at least one memory area called the "stack" and one area called the "heap" (commonly every process has one heap + one stack per thread. There MAY be more segments, but this is implementation dependent and it does not matter for the explanation here). On the stack things like you function's arguments and your local variables are saved. On the heap are variables saved that's size and lifetime cannot be determined by the compiler at compile time (that would be in Java everything that you use the "new"-Operator on. Example:

public void bar(String hi, int myInt)
{
  String foo = new String("foobar");
}

in this example are two String objects: (referenced by "foo" and "hi"). Both these objects are on the heap (you know this, because at some point both Strings were allocated using "new". And in this example 3 values are on the stack. This would be the value of "myInt", "hi" and "foo". It is important to realize that "hi" and "foo" don't really contain Strings directly, but instead they contain some id that tells them were on the heap they can find the String. (This is not as easy to explain using java because java abstracts a lot. In C "hi" and "foo" would be a Pointer which is actually just an integer which represents the address in the heap where the actual value is stored).

You might ask yourself why there is a stack and a heap anyway. Why not put everything in the same place. Explaining that unfortunately exceeds the scope of this answer. Read the book I linked ;-). The short version is that stack and heap are differently managed and the separation is done for reasons of optimization.

The size of stack and heap are limited. (On Linux execute ulimit -a and you'll get a list including "data seg size" (heap) and "stack size" (yeah... stack :-)).).

The stack is something that just grows. Like an array that gets bigger and bigger if you append more and more data. Eventually you run out of space. In this case you may end up writing in the memory area that does not belong to you anymore. And that would be extremely bad. So the operating systems notices that and stops the program if that happens. On Linux you get a "Segmenation fault" and on Windows you get an "Access violation".

In other languages like in C, you need to manage your memory manually. A tiny error can easily cause you to accidentally write into some space that does not belong to you. In Java you have "automatic memory management" which means that the JVM does all this for you. You don't need to care and that takes loads from your shoulders as a developer (it usually does. I bet there are people out there who would disagree about the "loads" part ;-)). This means that it /should/ be impossible to produce segmentation faults with java. Unfortunatelly the JVM is not perfect. Sometimes it has bugs and screws up. And then you get what you got.

这篇关于需要解释为什么会发生 EXCEPTION_ACCESS_VIOLATION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆